imtiazaasif

Mid point circle using radious

Jun 18th, 2022
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <GL/gl.h>
  2. #include <GL/glut.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5.  
  6. int r, p, x = 0, y;
  7. void display(void)
  8. {
  9.  
  10.     glClear(GL_COLOR_BUFFER_BIT);
  11.     glColor3f(1.0, 1.0, 1.0);
  12.     glBegin(GL_POINTS);
  13.  
  14.     p = 1 - r;
  15.  
  16.     while (x <= y)
  17.     {
  18.         if (p < 0)
  19.         {
  20.             x = x + 1;
  21.             y = y;
  22.             p = p + (2 * x + 1) + 1;
  23.         }
  24.         else
  25.         {
  26.             x = x + 1;
  27.             y = y - 1;
  28.             p = p + (2 * x + 1) + 1 - (2 * y);
  29.         }
  30.  
  31.         glVertex2i(x, y);
  32.         glVertex2i(y, x);
  33.         glVertex2i(-x, y);
  34.         glVertex2i(y, -x);
  35.         glVertex2i(-x, -y);
  36.         glVertex2i(-y, -x);
  37.         glVertex2i(x, -y);
  38.         glVertex2i(-y, x);
  39.     }
  40.  
  41.     glEnd();
  42.     glutSwapBuffers();
  43. }
  44. void init(void)
  45. {
  46.  
  47.     glClearColor(0.0, 0.0, 0.0, 0.0); /* select clearing (background) color */
  48.     glMatrixMode(GL_PROJECTION);      /* initialize viewing values */
  49.     glLoadIdentity();
  50.     glOrtho(-100, 100.0, -100, 100.0, -1, 1);
  51. }
  52.  
  53. int main(int argc, char **argv)
  54. {
  55.  
  56.     printf("Enter Radius value: ");
  57.     scanf("%d", &r);
  58.     y = r;
  59.  
  60.     glutInit(&argc, argv);
  61.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  62.     glutInitWindowSize(300, 300);
  63.     glutInitWindowPosition(100, 100);
  64.     glutCreateWindow("circle");
  65.     init();
  66.     glutDisplayFunc(display);
  67.     glutMainLoop();
  68.     return 0; /* ISO C requires main to return int. */
  69. }
Advertisement
Add Comment
Please, Sign In to add comment