Guest User

Untitled

a guest
Sep 14th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4. #include <GL/glut.h>
  5. #include<stdafx.h>
  6.  
  7. void gasket();
  8. void myinit()
  9. {
  10. glClearColor(1.0, 1.0, 1.0, 1.0);
  11. glColor3f(1.0, 1.0, 0.0);
  12. glMatrixMode(GL_PROJECTION);
  13. glLoadIdentity();
  14. gluOrtho2D(-10.0, 10.0, -10.0, 10.0);
  15. glMatrixMode(GL_MODELVIEW);
  16. }
  17.  
  18.  
  19. void draw( void )
  20. {
  21. int r=10;
  22. GLfloat theta;
  23.  
  24. glClear(GL_COLOR_BUFFER_BIT);
  25. glBegin(GL_POLYGON);
  26. for(theta=0; theta<=360; theta+=0.01)
  27. {
  28. glVertex2f(5*sin(theta*3.142/180), 2*cos(theta*3.142/180));
  29. }
  30. glEnd();
  31. glFlush();
  32. }
  33.  
  34.  
  35. void myMouse(int button, int state, int x,int y)
  36. {
  37. if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
  38. {
  39. draw();
  40.  
  41. }
  42. else if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
  43. {
  44. gasket();
  45.  
  46. }
  47.  
  48.  
  49.  
  50. }
  51.  
  52. void gasket()
  53. {
  54. #include<stdio.h>
  55. #include<stdlib.h>
  56. #include<math.h>
  57. #include <GL/glut.h>
  58. #include<stdafx.h>
  59.  
  60. void gasket();
  61. void myinit()
  62. {
  63. glClearColor(1.0, 1.0, 1.0, 1.0);
  64. glColor3f(1.0, 0.0, 0.0);
  65. glMatrixMode(GL_PROJECTION);
  66. glLoadIdentity();
  67. gluOrtho2D(-10.0, 10.0, -10.0, 10.0);
  68. glMatrixMode(GL_MODELVIEW);
  69. }
  70.  
  71.  
  72.  
  73. void draw( void )
  74. {
  75. int r=10;
  76. GLfloat theta;
  77.  
  78. glClear(GL_COLOR_BUFFER_BIT);
  79. glBegin(GL_POLYGON);
  80. for(theta=0; theta<=360; theta+=0.01)
  81. {
  82. glVertex2f(5*sin(theta*3.142/180), 2*cos(theta*3.142/180));
  83. }
  84. glEnd();
  85. glFlush();
  86. }
  87.  
  88.  
  89. void myMouse(int button, int state, int x,int y)
  90. {
  91. if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
  92. {
  93. draw();
  94.  
  95. }
  96. else if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
  97. {
  98. gasket();
  99.  
  100. }
  101.  
  102.  
  103.  
  104. }
  105.  
  106. void gasket()
  107. {
  108. GLfloat v[3][2] = {{1.0, 1.0}, {6.0, 1.0}, {3.5, 5.5}};
  109. int j, i;
  110.  
  111. glClear(GL_COLOR_BUFFER_BIT);
  112. glBegin(GL_POINTS);
  113. for(i=0; i<50000; i++)
  114. {
  115. j=rand()%3;
  116. p[0]=(p[0] + v[j][0])/2.0;
  117. p[1]=(p[1] + v[j][1])/2.0;
  118.  
  119. glVertex2fv(p);
  120. }
  121. glEnd();
  122. glFlush();
  123. }
  124.  
  125.  
  126.  
  127.  
  128. void display( void )
  129. {
  130.  
  131. glClear(GL_COLOR_BUFFER_BIT);
  132. glFlush();
  133. }
  134.  
  135.  
  136.  
  137. int main(int argc, char** argv)
  138. {
  139.  
  140.  
  141.  
  142. glutInit(&argc,argv);
  143. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  144. glutInitWindowSize(500,500);
  145. glutInitWindowPosition(0,0);
  146. glutCreateWindow("Mouse");
  147. glutDisplayFunc(display);
  148. glutMouseFunc(myMouse);
  149. myinit();
  150. glutMainLoop();
  151. return 0;
  152. }
  153.  
  154.  
  155.  
  156.  
  157. void display( void )
  158. {
  159.  
  160. glClear(GL_COLOR_BUFFER_BIT);
  161. glFlush();
  162. }
  163.  
  164.  
  165.  
  166. int main(int argc, char** argv)
  167. {
  168.  
  169.  
  170.  
  171. glutInit(&argc,argv);
  172. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  173. glutInitWindowSize(500,500);
  174. glutInitWindowPosition(0,0);
  175. glutCreateWindow("Mouse");
  176. glutDisplayFunc(display);
  177. glutMouseFunc(myMouse);
  178. myinit();
  179. glutMainLoop();
  180. return 0;
  181. }
Add Comment
Please, Sign In to add comment