Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // File triangles.cpp
- // Hugo Gallée
- // Sat Feb 25 13:02:15 CET 2012
- #include <GL/glut.h>
- #include <math.h>
- #define _USE_MATH_DEFINES
- void circle(float x, float y, float radius, int n) {
- float teta;
- glBegin (GL_LINE_LOOP);
- glColor3f (1.0, 0.0, 0.0);
- for (int i = 0; i < n; i++) {
- teta = i * 2 * M_PI / n;
- glVertex3f (radius * sin(teta) + x, radius * cos(teta) + y, 0.0);
- }
- glEnd();
- }
- void init (void) {
- // select clearing color
- glClearColor (1.0, 1.0, 1.0, 0.0);
- // initialize viewing values
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
- }
- void display(void) {
- // clear all pixels
- glClear (GL_COLOR_BUFFER_BIT);
- int nbSegments = 40;
- float teta = 1.0;
- float scale = 1.2;
- float radius = 0.4;
- float x = 0.5;
- float y = 0.5;
- while (radius > 0.02) {
- circle(x, y, radius, nbSegments);
- x += (radius - radius / scale) * sin(teta);
- y += (radius - radius / scale) * cos(teta);
- radius /= scale;
- circle(x, y, radius, nbSegments);
- teta += 0.5;
- }
- // Swap the buffers to show the oneon which we writed
- glutSwapBuffers();
- }
- /*
- * Declare initial window size, position, and display mode
- * (double buffer and RGB). Open window with "hello"
- * in its title bar. Call initialization routines.
- * Register callback function to display graphics.
- * Enter main loop and process events.
- */
- int main(int argc, char** argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize (500, 500);
- glutInitWindowPosition (100, 100);
- glutCreateWindow ("circles");
- init ();
- glutDisplayFunc(display);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement