Last active
November 18, 2018 01:48
-
-
Save Svastikkka/7c1a1b2db782eb159b0f7bbde21bfcf1 to your computer and use it in GitHub Desktop.
Computer Graphics sample projects written in c using OpenGl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<GL/glut.h> | |
#include<GL/gl.h> | |
#include<math.h> | |
void init(){ | |
glClearColor(1.0,1.0,1.0,1.0); | |
glMatrixMode(GL_PROJECTION); | |
gluOrtho2D(-100.0,100.0,-100.0,100.0); | |
} | |
void points(int xc,int yc,int x,int y) | |
{ | |
glColor3f(0.5,0.5,0.5); | |
glVertex2i(xc+x,yc+y); | |
glColor3f(1.0,0.0,1.0); | |
glVertex2i(xc-x,yc+y); | |
glColor3f(0.0,0.0,1.0); | |
glVertex2i(xc+x,yc-y); | |
glColor3f(0.0,1.0,0.0); | |
glVertex2i(xc-x,yc-y); | |
glColor3f(0.0,1.0,1.0); | |
glVertex2i(xc+y,yc+x); | |
glColor3f(0.0,0.0,0.0); | |
glVertex2i(xc-y,yc+x); | |
glColor3f(1.0,1.0,0.0); | |
glVertex2i(xc+y,yc-x); | |
glColor3f(1.0,0.0,0.0); | |
glVertex2i(xc-y,yc-x); | |
} | |
void circle(int ra) | |
{ | |
int x=0; | |
int y=ra; | |
int p=1-ra; | |
while(x<=y) | |
{ | |
x++; | |
p=p+2*x+1; | |
if(p>0) | |
{ | |
y--; | |
p=p-2*y; | |
} | |
points(0,0,x,y); | |
} | |
} | |
void midpointcircle(void) | |
{ | |
glClear(GL_COLOR_BUFFER_BIT); | |
glPointSize(2.0); | |
glBegin(GL_POINTS); | |
glColor3f(0.0,1.0,0.0); | |
circle(25); | |
circle(50); | |
glEnd(); | |
glLineWidth(1.0); | |
glBegin(GL_LINES); | |
// this is create a vertical line | |
glVertex2i(-20,-52); | |
glVertex2i(20,-52); | |
// this is create a horizontal line | |
glVertex2i(-20,-52); | |
glVertex2i(-20,-80); | |
glVertex2i(20,-52); | |
glVertex2i(20,-80); | |
// this is create a vertical line | |
glVertex2i(-40,-80); | |
glVertex2i(40,-80); | |
// this is create a horizontal line | |
glVertex2i(-40,-80); | |
glVertex2i(-40,-100); | |
// this is create a vertical line | |
glVertex2i(-40,-100); | |
glVertex2i(40,-100); | |
// this is create a horizontal line | |
glVertex2i(40,-80); | |
glVertex2i(40,-100); | |
glEnd(); | |
glFlush(); | |
} | |
int main(int argc, char**argv) | |
{ | |
glutInit(&argc,argv); | |
glutInitWindowPosition(20,20); | |
glutInitWindowSize(512,512); | |
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); | |
glutCreateWindow(" Manshu Sharma ' s circle"); | |
glutDisplayFunc(midpointcircle); | |
glutMainLoop(); | |
return 0; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<GL/glut.h> | |
#include<GL/gl.h> | |
#include<math.h> | |
void init() | |
{ | |
glClearColor(100.0,100.0,100.0,100.0); | |
glMatrixMode(GL_PROJECTION); | |
gluOrtho2D(-100.0,100.0,-100.0,100.0); | |
} | |
void watch() | |
{ | |
glClear(GL_COLOR_BUFFER_BIT); | |
float x1=0.0,y1=0.0,r=80.0,angle,x2,y2; | |
glBegin(GL_TRIANGLE_FAN); | |
glColor3f(6.0,6.0,6.0); | |
glLineWidth(10.0); | |
glVertex2f(x1,y1); | |
for(angle=0;angle<=360;angle++) | |
{ | |
x2=x1+r*cos(angle); | |
y2=y1+r*sin(angle); | |
glVertex2f(x2,y2); | |
} | |
glEnd(); | |
glBegin(GL_LINE_LOOP); | |
glColor3f(0.0,0.0,0.0); | |
glVertex2i(-5,65); | |
glVertex2i(-5,75); | |
glEnd(); | |
glBegin(GL_LINES); | |
glColor3f(0.0,0.0,0.0); | |
glVertex2i(0,75); | |
glVertex2i(5,75); | |
glVertex2i(5,75); | |
glVertex2i(5,70); | |
glVertex2i(5,70); | |
glVertex2i(0,70); | |
glVertex2i(0,70); | |
glVertex2i(0,65); | |
glVertex2i(0,65); | |
glVertex2i(5,65); | |
glEnd(); | |
glBegin(GL_LINES); | |
glColor3f(0.0,0.0,0.0); | |
glVertex2i(65,5); | |
glVertex2i(75,5); | |
glVertex2i(75,5); | |
glVertex2i(75,-5); | |
glVertex2i(75,-5); | |
glVertex2i(65,-5); | |
glVertex2i(67,0); | |
glVertex2i(75,0); | |
glEnd(); | |
glBegin(GL_LINES); | |
glColor3f(0.0,0.0,0.0); | |
glVertex2i(-5,-65); | |
glVertex2i(5,-65); | |
glVertex2i(-5,-65); | |
glVertex2i(-5,-75); | |
glVertex2i(-5,-75); | |
glVertex2i(5,-75); | |
glVertex2i(5,-75); | |
glVertex2i(5,-70); | |
glVertex2i(5,-70); | |
glVertex2i(-5,-70); | |
glEnd(); | |
glBegin(GL_LINES); | |
glColor3f(0.0,0.0,0.0); | |
glVertex2i(-75,5); | |
glVertex2i(-65,5); | |
glVertex2i(-65,5); | |
glVertex2i(-65,-5); | |
glVertex2i(-65,-5); | |
glVertex2i(-75,-5); | |
glVertex2i(-75,5); | |
glVertex2i(-75,0); | |
glVertex2i(-75,0); | |
glVertex2i(-65,0); | |
glEnd(); | |
glBegin(GL_LINES); | |
glColor3f(0.0,0.0,0.0); | |
glVertex2i(0,0); | |
glVertex2i(0,60); | |
glVertex2i(0,0); | |
glVertex2i(-35,0); | |
glVertex2i(0,0); | |
glVertex2i(30,45); | |
glEnd(); | |
glFlush(); | |
} | |
int main(int argc,char **argv) | |
{ | |
glutInit(&argc,argv); | |
glutInitWindowPosition(20,20); | |
glutInitWindowSize(200,200); | |
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); | |
glutCreateWindow("Manshu'S clock"); | |
init(); | |
glutDisplayFunc(watch); | |
glutMainLoop(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*this program is design by manshu sharma as help to other students you can copy this and display as your project | |
*step1 :- int rx=80, ry=20, xc=0, yc=ry;// radius x ,radius y center of x = 0 center of y = radius of y | |
*step2 :- float p=(ry*ry)-(rx*rx*ry)+((0.25)*(rx*rx)); | |
*step3 :- apply a while loop with condition (2*ry*ry*xc)<=(2*rx*rx*yc) | |
*step4 :- In that while loop apply two conditions p<0 | |
*step5 :- while((2*ry*ry*xc)<=(2*rx*rx*yc)){ | |
* if(p<0){ | |
* xc++; | |
* p=p+(2*ry*ry*xc)+(3*ry*ry); | |
* } | |
* else{ | |
* xc++; | |
* yc--; | |
* | |
* p=p+((2*ry*ry*xc)+(3*ry*ry))-((2*rx*rx*yc)+(2*rx*rx)); | |
* } | |
* glVertex2i(xc,yc); | |
* glVertex2i(xc,-yc); | |
* glVertex2i(-xc,yc); | |
* glVertex2i(-xc,-yc); | |
* } | |
*step6 :- apply a 2 while loop with condition yc!=0 | |
*step7 :- | |
*/ | |
#include<GL/glut.h> | |
#include<GL/gl.h> | |
#include<math.h> | |
void init(void) | |
{ | |
glClearColor(1.0,1.0,1.0,0.0); | |
glMatrixMode(GL_PROJECTION); | |
gluOrtho2D(-100.0,100.0,-100.0,100.0); | |
} | |
void ellipsefunc() | |
{ | |
int rx=80, ry=20, xc=0, yc=ry;// radius x ,radius y center of x = 0 center of y = radius of y | |
float p=(ry*ry)-(rx*rx*ry)+((0.25)*(rx*rx)); //formula 1 | |
glClear(GL_COLOR_BUFFER_BIT); | |
glColor3f(0.0,0.0,1.0); | |
glPointSize(2.0); | |
glBegin(GL_POINTS); | |
while((2*ry*ry*xc)<=(2*rx*rx*yc)){ | |
if(p<0){ | |
xc++; | |
p=p+(2*ry*ry*xc)+(3*ry*ry); | |
} | |
else{ | |
xc++; | |
yc--; | |
p=p+((2*ry*ry*xc)+(3*ry*ry))-((2*rx*rx*yc)+(2*rx*rx)); | |
} | |
glVertex2i(xc,yc); | |
glVertex2i(xc,-yc); | |
glVertex2i(-xc,yc); | |
glVertex2i(-xc,-yc); | |
} | |
float p1 = (ry*ry*(xc+0.5)*(xc+0.5))+(rx*rx*(yc-1)*(yc-1))-(rx*rx*ry*ry*ry);//formula 2 | |
glClear(GL_COLOR_BUFFER_BIT); | |
glColor3f(1.0,0.0,0.0); | |
glPointSize(2.0); | |
glBegin(GL_POINTS); | |
while(yc!=0){ | |
if(p1>0){ | |
yc--; | |
p1=p1-((2*rx*rx*yc)-(2*rx*rx))+(rx*rx); | |
} | |
else{ | |
yc--; | |
xc++; | |
p1=p1-((2*rx*rx*yc)+(2*rx*rx))+(rx*rx)-((2*ry*ry*xc)-(2*ry*ry)); | |
} | |
glVertex2i(xc,yc); | |
glVertex2i(xc,-yc); | |
glVertex2i(-xc,yc); | |
glVertex2i(-xc,-yc); | |
} | |
glEnd(); | |
glFlush(); | |
} | |
int main(int argc ,char **argv) | |
{ | |
glutInit(&argc, argv); | |
glutInitWindowPosition(2,2); | |
glutInitWindowSize(700,700); | |
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); | |
glutCreateWindow(" Manshu's Ellipse"); | |
init(); | |
glutDisplayFunc(ellipsefunc); | |
glutMainLoop(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Computer Graphics sample projects written in c using OpenGl