Skip to content

Instantly share code, notes, and snippets.

@SohanChy
Created March 1, 2018 20:05
Show Gist options
  • Save SohanChy/3199026df1b11c4ff1402b8daeda00fc to your computer and use it in GitHub Desktop.
Save SohanChy/3199026df1b11c4ff1402b8daeda00fc to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <math.h>
void eightSideDisp(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 0.0, 1.0);
glPointSize(5.0);
int x = 0 ; int y = 100 ; int d = 1 - 100;
while(y>x)
{
if(d<0)
{
d = d + 2*x + 3 ;
}
else
{
d = d + 2*(x-y) + 5 ;
y--;
}
x++;
glBegin(GL_POINTS);
glVertex2i(x,y);
glVertex2i(y,x);
glVertex2i(y,-x);
glVertex2i(x,-y);
glVertex2i(-x,-y);
glVertex2i(-y,-x);
glVertex2i(-y,x);
glVertex2i(-x,y);
glEnd();
}
glFlush ();
}
void midpoint(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 1.0, 1.0);
glPointSize(5.0);
int x = 0 ; int r = 6 * 10 ; int d = 1 - r, y = r, a = 3, b = -2;
while(y>x)
{
if(d<0)
{
d = d + 2*x + 3 ;
}
else
{
d = d + 2*(x-y) + 5 ;
y--;
}
x++;
glBegin(GL_POINTS);
glVertex2i(x+a,y+b);
glVertex2i(y+a,x+b);
glVertex2i(y+a,-x+b);
glVertex2i(x+a,-y+b);
glVertex2i(-x+a,-y+b);
glVertex2i(-y+a,-x+b);
glVertex2i(-y+a,x+b);
glVertex2i(-x+a,y+b);
glEnd();
}
glFlush ();
}
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glColor3f(0.0f, 0.0f, 0.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluOrtho2D(-320.0, 320.0, -240.0, 240.0);
}
main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (640, 480);
glutInitWindowPosition (100, 150);
glutCreateWindow ("Circle");
glutDisplayFunc(midp);
myInit();
glutMainLoop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment