Im trying to draw a fractal image based on equation
note:k is in subscript
z0=z
zk=zk-1+z0
following is the code i came up with but it wont draw anything
im a total newb so dont leave out obvious mistakes
#include <GL/glut.h>
GLfloat winHeight=500, winWidth=500;
GLfloat xcmin=-2.0,xcmax=2.0; //area of rectangle in complex
plane
GLfloat ycmin=-2.0,ycmax=-2.0;
GLint maxIter=1000,count=0;
struct color { GLfloat r,g,b; };
// sotre complex number
class cnum {
public:
GLfloat x,y;
};
void init()
{
glClearColor(1.0,1.0,1.0,0.0);
glPointSize(4);
}
void plotPoint(cnum z)
{
glBegin(GL_POINTS);
glVertex2f(z.x,z.y);
glEnd();
}
void test()
{
color ptColor;
cnum z,z0;
z0.x=xcmin;
z0.y=ycmin;
GLfloat xcinc=0.025,ycinc=0.025; // increments
for(z.x=xcmin; z.x<xcmax; z.x+=xcinc)
for(z.y=ycmin; z.y<ycmax; z.y+=ycinc) {
count=0;
// while magnitude < 4 and max iterations not reached
while(z.x*z.x*+z.y*z.y <=4 && count <=maxIter) {
z.x=z.x*z.x+z0.x; // z.x squared + z0
z.y=z.y*z.y+z0.y;
count++;
}
if (count=0){
ptColor.r=1.0;
ptColor.g=ptColor.b=0.0;
}
else if(count > maxIter/2) {
ptColor.g=1.0;
ptColor.r=ptColor.b=0.0;
}
else if(count > maxIter) {
ptColor.b=1.0;
ptColor.r=ptColor.g=0.0;
}
glColor3f(ptColor.r,ptColor.g,ptColor.b);
plotPoint(z);
}
}
void displayFcn()
{
glClear(GL_COLOR_BUFFER_BIT);
test();
glFlush();
}
void main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(50,50);
glutInitWindowSize(winWidth,winHeight);
glutCreateWindow(“Test”);
init();
glutDisplayFunc(displayFcn);
glutMainLoop();
}
many thx
Raza