Vous êtes sur la page 1sur 2

#include <iostream>

#include<GL/glut.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
using namespace std;
class complex
{
private:
float re,im;
public:
complex()
{
re=0;im=0;
}
public:
complex operator +(complex a)
{
complex res;
res.re = re+a.re;
res.im= im+a.im;
return res;
}
complex operator * (complex a)
{
complex res;
res.re=re*a.re -im*a.im;
res.im=re*a.im+im*a.re;
return res;
}
void set(float a,float b)
{
re=a;im=b;}
float abs()
{
return re*re+im*im;}
};
int xmax=300,xmin=100,ymax=300,ymin=100;
int limit=50;
complex c;
/*int colors[][3]={0,60,80,
6,31,55,
13,19,42,
17,36,25,
19,17,33,
33,6,20,
48,22,55,
55,46,0,
80,20,20,
80,41,54,
78,96,15,
93,36,26,
99,71,8,
18,55,34,
68,100,18,
42,56,14
};*/
//int colors[][3]={0,0,0,50,90,30,100,0,100};
//int colors[][3]={42,56,14,90,72,16,93,0,0};
int colors[][3]={18,55,34,99,71,8,10,97,12};
void init()
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0f,0.0f,0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,600,0,600);

glEnable(GL_SHADE_MODEL);
glShadeModel(GL_SMOOTH);
}
int mandelbrot_test(complex a)
{
int i;
complex temp;
for(i=1;i<=limit&&temp.abs()<4;i++)
{
temp=temp*temp+c;
}
if(i>limit)
return 1;
return 0;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.52f,0.08f,0.40f);
glPointSize(2);
complex temp;
srand(time(NULL));
int res,i,j,rands,cnt=0;
float val;
glBegin(GL_POINTS);
for(i=-300;i<=300;i++)
for(j=-250;j<=250;j++)
{
c.set(i*1.0/200,j*1.0/250);
res=mandelbrot_test(temp);
if(res)
{
val=temp.abs();
if(cnt%3==0)
{ rands=rand()%3;
}
cnt++;
glColor3f(colors[rands][0]*0.01,0.01*col
ors[rands][1],0.01*colors[rands][2]);
glVertex2d(i+300,j+250);
}
}
glEnd();
glFlush();
}
int main(int argc,char* argv[])
{
float a,b;
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(600,600);
glutCreateWindow("Mandelbrot Set");
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}

Vous aimerez peut-être aussi