Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/gl.h>
- #include <GL/glut.h>
- #include <math.h>
- #include <stdlib.h>
- int n;
- float a;
- void display();
- static void init()
- {
- /* set clear color to white */
- glClearColor (1.0, 1.0, 1.0, 0.0);
- /* set fill color to black */
- glColor3f(0.0, 0.0, 0.0);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- gluOrtho2D(-0.5, 1.5, -0.5, 1.5);
- } /* end init */
- int main(int argc, char* argv[])
- {
- if(argc>1)
- n=atoi(argv[1]);
- else
- n=3;
- glutInit(&argc,argv);
- glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize(600, 600);
- glutInitWindowPosition(100,100);
- glutCreateWindow(argv[0]);
- glutDisplayFunc(display);
- init();
- glutMainLoop();
- return 0;
- }
- void display()
- {
- glClear (GL_COLOR_BUFFER_BIT);
- void etiop(float, float, float, float, int);
- etiop(0.0,0.0,1.0,0,n);
- glFlush();
- }
- void etiop(float x1, float y1, float x2, float y2, int n)
- {
- float xa,ya,xb,yb,xc,yc,xd,yd,xdg,ydg,xdd,ydd,k,d;
- if(n<=0)
- {
- glBegin(GL_LINES);
- glVertex2f(x1,y1);
- glVertex2f(x2,y2);
- glEnd();
- return;
- }
- else
- {
- xa=x1+(x2-x1)/5;
- ya=y1+(y2-y1)/5;
- xb=x1+(x2-x1)*4/5;
- yb=y1+(y2-y1)*4/5;
- k=atan2(yb-ya,xb-xa);
- d= sqrt (( xb - xa) *(xb - xa)+(yb - ya) *(yb - ya) ) ;
- d = d/sqrt(2);
- xc=xa+d*cos(k+M_PI/4);
- yc=ya+d*sin(k+M_PI/4);
- xd=xa+d*cos(k-M_PI/4);
- yd=ya+d*sin(k-M_PI/4);
- d= sqrt (( xa - x1) *(xa - x1)+(ya - y1) *(ya - y1) ) ;
- k=atan2(yb-ya,xb-xa);
- xdg=xc+d*cos(k+M_PI/2);
- ydg=yc+d*sin(k+M_PI/2);
- xdd=xd+d*cos(k-M_PI/2);
- ydd=yd+d*sin(k-M_PI/2);
- etiop(xc,yc,xdg,ydg,n-1);
- etiop(xd,yd,xdd,ydd,n-1);
- etiop(x1,y1,xa,ya,n-1);
- etiop(xa,ya,xd,yd,n-1);
- etiop(xd,yd,xb,yb,n-1);
- etiop(xa,ya,xc,yc,n-1);
- etiop(xc,yc,xb,yb,n-1);
- etiop(xb,yb,x2,y2,n-1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement