poniedziałek, 10 listopada 2014
poniedziałek, 22 września 2014
Java Simple Fractal
This is simple fractal in Java Applet. I make cool draw for circle and simple algorithm
CODE:
import java.applet.Applet;
import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
public class Fraktal extends Applet {
/*
* numer version is not necessary but eclipse want it linia nie wymagana ale
* eclipse chce ja
*/
private static final long serialVersionUID = -4516025624539478755L;
int level = 0; // create stages etapy tworzenia
public void init() { // for applet main main apletów
setBackground(new Color(244, 235, 155)); // random color :)
}
public boolean mouseDown(Event ev, int x, int y) {
/*
* MOUSE left next level, right previous level MYSZKA lewy nastepny
* poziom prawy poprzedni
*/
if (!ev.metaDown())
level += 1;
else
level = 0;
repaint();
return true;
}
public void paint(Graphics g) {
g.setColor(Color.BLUE);
drawCircle(g, 280, 20, 700, level);
}
/*
* this is all operation wszystko co potrzeba tu jest
*/
public void drawCircle(Graphics g, int x, int y, int p, int level) {
int help;
g.drawOval(x, y, p, p);
if (level == 0)
return;
level -= 1;
if (p > 2) {
help = p / 4;
// drawCircle(g, x + help, y + help, 2 * help, level); //start
// version wersja poczatkowa
drawCircle(g, x + 3 * help, y + help, 2 * help, level);
drawCircle(g, x - help, y + help, 2 * help, level);
drawCircle(g, x + help, y + 3 * help, 2 * help, level);
drawCircle(g, x + help, y - help, 2 * help, level);
}
}
}
import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
public class Fraktal extends Applet {
/*
* numer version is not necessary but eclipse want it linia nie wymagana ale
* eclipse chce ja
*/
private static final long serialVersionUID = -4516025624539478755L;
int level = 0; // create stages etapy tworzenia
public void init() { // for applet main main apletów
setBackground(new Color(244, 235, 155)); // random color :)
}
public boolean mouseDown(Event ev, int x, int y) {
/*
* MOUSE left next level, right previous level MYSZKA lewy nastepny
* poziom prawy poprzedni
*/
if (!ev.metaDown())
level += 1;
else
level = 0;
repaint();
return true;
}
public void paint(Graphics g) {
g.setColor(Color.BLUE);
drawCircle(g, 280, 20, 700, level);
}
/*
* this is all operation wszystko co potrzeba tu jest
*/
public void drawCircle(Graphics g, int x, int y, int p, int level) {
int help;
g.drawOval(x, y, p, p);
if (level == 0)
return;
level -= 1;
if (p > 2) {
help = p / 4;
// drawCircle(g, x + help, y + help, 2 * help, level); //start
// version wersja poczatkowa
drawCircle(g, x + 3 * help, y + help, 2 * help, level);
drawCircle(g, x - help, y + help, 2 * help, level);
drawCircle(g, x + help, y + 3 * help, 2 * help, level);
drawCircle(g, x + help, y - help, 2 * help, level);
}
}
}
środa, 6 sierpnia 2014
C Factorial large numbers approximate method
#include <math.h>
double factorial(int n)
{
double result=1;
if(n>30)
result=pow(n/M_E,n)*sqrt(2*M_PI*n); //FOR BIG NUMBERS
else
for(int i=1;i<=n;i++) //FOR SMALL NUMBERS
{
result*=i;
}
return result;
}
Returning
Hi,
Some information.
I begin to publish again. I have two emails, so posts are published by two names(both mine).
I write in English, because most people who read my blog don`t speak Polish and translaction isn`t good for program code.
If you find fault but you have problem with my code or You want my help with something problem write to me.
I`m sorry for my English , please corect mi if You can :)
Some information.
I begin to publish again. I have two emails, so posts are published by two names(both mine).
I write in English, because most people who read my blog don`t speak Polish and translaction isn`t good for program code.
If you find fault but you have problem with my code or You want my help with something problem write to me.
I`m sorry for my English , please corect mi if You can :)
piątek, 10 stycznia 2014
C++ function templates 1
#include <iostream>
using namespace std;
template <class A>
A dodaj(A a,A b)
{
return a+b;
}
int main()
{
cout << "function templates!" << endl;
cout<<"int="<<dodaj(1,2)<<endl;
cout<<"float="<<dodaj(1.01,2.11)<<endl;
cout<<"char="<<dodaj(' ','b')<<endl;
return 0;
}
using namespace std;
template <class A>
A dodaj(A a,A b)
{
return a+b;
}
int main()
{
cout << "function templates!" << endl;
cout<<"int="<<dodaj(1,2)<<endl;
cout<<"float="<<dodaj(1.01,2.11)<<endl;
cout<<"char="<<dodaj(' ','b')<<endl;
return 0;
}
wtorek, 7 stycznia 2014
C++ Constructor & Descrutor
_____________________________________________
#include <iostream>
using namespace std;
class A
{
public:
A()
{
cout << "Constructor A" << endl;
}
~A()
{
cout << "Destructor A" << endl;
}
private:
int x;
};
class B:public A
{
public:
B():A()
{
cout << "Constructor B" << endl;
}
~B()
{
cout << "Destructor B" << endl;
}
};
int main()
{
B o1;
return 0;
}
#include <iostream>
using namespace std;
class A
{
public:
A()
{
cout << "Constructor A" << endl;
}
~A()
{
cout << "Destructor A" << endl;
}
private:
int x;
};
class B:public A
{
public:
B():A()
{
cout << "Constructor B" << endl;
}
~B()
{
cout << "Destructor B" << endl;
}
};
int main()
{
B o1;
return 0;
}
C++ virtual inheritance /c++ dziedziczenie virtualne
:)
________________________________________________
#include <iostream>
using namespace std;
class A
{
public:
void read()
{
cout << "This is A" << endl;
}
private:
};
class B:virtual public A
{
public:
private:
};
class C:virtual public A
{
public:
private:
};
class D:public B,public C
{
};
int main()
{
D o1;
o1.read();
return 0;
}
________________________________________________
#include <iostream>
using namespace std;
class A
{
public:
void read()
{
cout << "This is A" << endl;
}
private:
};
class B:virtual public A
{
public:
private:
};
class C:virtual public A
{
public:
private:
};
class D:public B,public C
{
};
int main()
{
D o1;
o1.read();
return 0;
}
środa, 1 stycznia 2014
C++ visual function / C++ visualna funkcja
This is visual function
__________________________________________________________
#include <iostream>
using namespace std;
class A
{
public:
virtual void read()
{
cout << "This is A" << endl;
}
private:
};
class B:public A
{
public:
void read()
{
cout << "This is B" << endl;
}
private:
};
class C:public A
{
public:
void read()
{
cout << "This is C" << endl;
}
private:
};
int main()
{
//standard use
A o1;
o1.read();
B o2;
o2.read();
C o3;
o3.read();
//Vitualization
cout << "Virtual" << endl;
A *wsk=&o1;
wsk->read();
wsk=&o2;
wsk->read();
wsk=&o3;
wsk->read();
return 0;
}
__________________________________________________________
#include <iostream>
using namespace std;
class A
{
public:
virtual void read()
{
cout << "This is A" << endl;
}
private:
};
class B:public A
{
public:
void read()
{
cout << "This is B" << endl;
}
private:
};
class C:public A
{
public:
void read()
{
cout << "This is C" << endl;
}
private:
};
int main()
{
//standard use
A o1;
o1.read();
B o2;
o2.read();
C o3;
o3.read();
//Vitualization
cout << "Virtual" << endl;
A *wsk=&o1;
wsk->read();
wsk=&o2;
wsk->read();
wsk=&o3;
wsk->read();
return 0;
}
C++ inheritance basics / C++ dziedziczenie podstawy
Start inheritances
_________________________________________________________________
#include <iostream>
using namespace std;
class A
{
public:
A(int X,int Y):x(X),y(Y){}
A operator =(const A &wzor);
void write();
protected:
private:
int x,y;
};
void A::write()
{
cout <<"Data"<<endl<< "x=" <<x<<endl<<"y="<<y<< endl;
}
A A::operator =(const A &wzor)
{
x=wzor.x;
y=wzor.y;
return *this;
}
/*-----------------------------------------------------------------------------*/
class B:public A
{
public:
B(int X, int Y, int Z):A(X,Y),z(Z){}
B operator =(const B &wzor);
void write();
protected:
private:
int z;
};
void B::write()
{
A::write();
cout << "z=" <<z<<endl;
}
B B::operator =(const B &wzor)
{
(*this).A::operator=(wzor);
z=wzor.z;
return *this;
}
int main()
{
A o1(1,2);
o1.write();
B o2(12,44,66);
o2.write();
B o3=o2;
o3.write();
return 0;
}
_________________________________________________________________
#include <iostream>
using namespace std;
class A
{
public:
A(int X,int Y):x(X),y(Y){}
A operator =(const A &wzor);
void write();
protected:
private:
int x,y;
};
void A::write()
{
cout <<"Data"<<endl<< "x=" <<x<<endl<<"y="<<y<< endl;
}
A A::operator =(const A &wzor)
{
x=wzor.x;
y=wzor.y;
return *this;
}
/*-----------------------------------------------------------------------------*/
class B:public A
{
public:
B(int X, int Y, int Z):A(X,Y),z(Z){}
B operator =(const B &wzor);
void write();
protected:
private:
int z;
};
void B::write()
{
A::write();
cout << "z=" <<z<<endl;
}
B B::operator =(const B &wzor)
{
(*this).A::operator=(wzor);
z=wzor.z;
return *this;
}
int main()
{
A o1(1,2);
o1.write();
B o2(12,44,66);
o2.write();
B o3=o2;
o3.write();
return 0;
}
Subskrybuj:
Posty (Atom)
