[OpenGL] Case Study 01: Sierpinski lawn pad Program

Source: Internet
Author: User
// A.1 Sierpinski fill pad Program/* Two-dimen1_sierpinski gasket * // * generated using randomly selected vertices * // * And bisection */# include <Gl/glut. h> # include <windows. h> // no textbook. If rand () is not added, an error is returned. I do not know why/* you may have to change the include to <glut. h> orelsewhere depending on where it is stored on your system * // * glut. h usually has encoded ded for GL. H and Glu. H */void myinit (void) {/* attributes */glclearcolor (1.0, 1.0, 1.0, 1.0);/* white background */glcolor3f (1.0, 0.0, 0.0 ); /* draw in red * // * set up viewing * // * 50.0x50.0 camera coordinate window with origin lower left */glmatrixmode (gl_projection); glloadidentity (); gluortho2d (0.0, 50.0, 0.0, 50.0); glmatrixmode (gl_modelview);} void display (void) {/* a triangle */glfloat vertices [3] [2] = {0.0, 0.0}, {25.0, 50.0}, {50.0, 0.0}; int I, j, k; int rand ();/* standard random number generator */glfloat P [2] = {7.5, 5.0 }; /* an arbitrary initial point inside traingle */glclear (gl_color_buffer_bit);/* clear the window */glbegin (gl_points ); /* compute and plots 5000 new points */For (k = 0; k <5000; k ++) {J = rand () % 3; /* pick a vertex at random * // * compute point halfway between selected vertex and old point */P [0] = (P [0] + vertices [J] [0]) /2.0; P [1] = (P [1] + vertices [J] [1])/2.0;/* plot new point */glvertex2fv (p );} glend (); glflush ();/* clear buffers */} void main (INT argc, char ** argv) {/* standard glut initialization */gluinit (& argc, argv); gluinitdisplaymode (glu_single | glu_rgb);/* default, not needed */gluinitwindowsize (500,500);/* 500 × 500 pixel window */gluinitwindowposition ); /* place window top left on display */FIG ("Sierpinski gasket");/* window title */FIG (Display ); /* display callback invoked when window opened */myinit ();/* Set attributes */FIG ();/* enter event loop */}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.