#include #include #include #include #include "screen.h" #include float XPoint(float,float, float,float, float,float); float YPoint(float,float, float,float, float,float); void fractal(float,float,int,const float); void fname(char [], const int); const float PI=3.1415927; Screen S(600,600); int main(){ ofstream scriptfile("makegif"); ofstream mergegifs("mergegif"); ofstream removal("gifremoval"); char name[10]; S.setrect(-1.2,-1.2,2.4,2.4); mergegifs << "gifsicle --delay 50 -O2 -l "; for (int i=0;i<48;i++){ fname(name,i); fractal(0,0,10,PI*i/24); scriptfile << "convert " << name << ".xpm " << name << ".gif"<< endl; scriptfile << "rm " << name << ".xpm" << endl; mergegifs << name << ".gif "; removal << "rm " << name << ".gif" << endl; S.matrix2xpm(strcat(name,".xpm")); cout << "Done: Image " << i << endl; S.clear(); } mergegifs << "> anim.gif"; return 0; } float XPoint(float xc,float yc, float theta,float scale, float x,float y){ return ((x*cos(theta)-y*sin(theta))*scale+xc); } float YPoint(float xc,float yc, float theta,float scale, float x,float y){ return ((x*sin(theta)+y*cos(theta))*scale+yc); } void fractal(float x, float y, int depth, const float ang){ if (depth==0){ S.plotxy(x,y); } else { fractal(XPoint(0,0,0,.5,x,y),YPoint(0,0,0,.5,x,y),depth-1, ang); fractal(XPoint(0,.5,0,.5,x,y),YPoint(0,.5,0,.5,x,y),depth-1, ang); fractal(XPoint(.5*sin(ang),.5*cos(ang),-ang,.5,x,y),YPoint(.5*sin(ang),.5*cos(ang),-ang,.5,x,y),depth-1, ang); fractal(XPoint(-.5*sin(ang),.5*cos(ang),ang,.5,x,y),YPoint(-.5*sin(ang),.5*cos(ang),ang,.5,x,y),depth-1, ang); } } void fname(char name[], const int n){ strcpy(name,"aa");; name[0]+=(n/26)%26; name[1]+=n%26; }