0% found this document useful (0 votes)
191 views2 pages

OpenGL Animated Circles

This C++ code defines functions to draw circles of increasing radii at a central point using OpenGL. It initializes OpenGL settings, defines a structure for circle center points and a function to draw a circle given a center point and radius. The main function sets up an OpenGL window, calls functions to initialize drawing and display animated circles, and enters a redraw loop. Each frame, circles are drawn with incrementally larger radii starting from 0 up to 180 units before resetting.

Uploaded by

Vishnu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views2 pages

OpenGL Animated Circles

This C++ code defines functions to draw circles of increasing radii at a central point using OpenGL. It initializes OpenGL settings, defines a structure for circle center points and a function to draw a circle given a center point and radius. The main function sets up an OpenGL window, calls functions to initialize drawing and display animated circles, and enters a redraw loop. Each frame, circles are drawn with incrementally larger radii starting from 0 up to 180 units before resetting.

Uploaded by

Vishnu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <GL/glut.

h>
#include <math.h>

struct Point {
GLint x;
GLint y;
};

void init() {
glClearColor(1.0, 1.0, 1.0, 0.0);
glColor3f(0.0f, 0.0f, 0.0f);
glPointSize(1.0f);
gluOrtho2D(0.0f, 640.0f, 0.0f, 480.0f);
}

void draw_circle(Point pC, GLfloat radius) {


GLfloat step = 1/radius;
GLfloat x, y;

for(GLfloat theta = 0; theta <= 360; theta += step) {


x = pC.x + (radius * cos(theta));
y = pC.y + (radius * sin(theta));
glVertex2i(x, y);
}
}

Point pCenter = {320, 240};


float dRadius = 1;

float radius[3] = {
0.0f,
60.0f,
120.0f
};

void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
for(int i = 0; i < 3; i++) {
draw_circle(pCenter, radius[i]);
radius[i]+=dRadius;

if(radius[i] > 180)


radius[i] = 0;
}
glEnd();
glFlush();
}

void Timer(int value) {


glutTimerFunc(33, Timer, 0);
glutPostRedisplay();
}

int main(int argc, char **argv) {


glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(200, 200);
glutInitWindowSize(640, 480);
glutCreateWindow("Square");
glutDisplayFunc(display);
init();
Timer(0);
glutMainLoop();

return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy