Guest User

Untitled

a guest
Jan 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #include <math.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5.  
  6. #include "glut.h"
  7.  
  8.  
  9. float point[2];
  10. int points = 10000000;
  11.  
  12. void f1(){
  13. point[0] = point[0]*0.5;
  14. point[1] = point[1]*0.5;
  15. }
  16. void f2(){
  17. point[0] = point[0]*0.5+0.5;
  18. point[1] = point[1]*0.5;
  19. }
  20.  
  21. void f3(){
  22. point[0] = point[0]*0.5;
  23. point[1] = point[1]*0.5+0.5;
  24. }
  25.  
  26.  
  27. void p1(){
  28. point[0] = 0;
  29. point[1] = 0.16*point[1];
  30. }
  31. void p2(){
  32. point[0] = 0.85*point[0]+0.04*point[1];
  33. point[1] = -0.04*point[0]+0.85*point[1] + 1.6;
  34. }
  35. void p3(){
  36. point[0] = 0.2*point[0] - 0.26*point[1];
  37. point[1] = 0.23*point[0] + 0.22*point[1] + 1.6;
  38. }
  39. void p4(){
  40. point[0] = -0.15*point[0] + 0.28*point[1];
  41. point[1] = 0.26*point[0] + 0.24*point[1] + 0.44;
  42. }
  43.  
  44.  
  45. void set_rand_point(){
  46. //point[0] = (rand() % 1000) /1000.0;
  47. //point[1] = (rand() % 1000) /1000.0;
  48. point[0] = 0;
  49. point[1] = 0;
  50. }
  51.  
  52. int probability(){
  53. int r = rand() % 100;
  54. if(r < 1)
  55. return 0;
  56. if(r < 86)
  57. return 1;
  58. if(r < 93)
  59. return 2;
  60. return 3;
  61.  
  62. }
  63.  
  64. void render_scene(void) {
  65. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  66.  
  67. glPointSize(1);
  68. glBegin(GL_POINTS);
  69. set_rand_point();
  70.  
  71. for(int i = 0; i < points; i++)
  72. {
  73. switch(probability()){
  74. case 0:
  75. p1();
  76. break;
  77.  
  78. case 1:
  79. p2();
  80. break;
  81.  
  82. case 2:
  83. p3();
  84. break;
  85.  
  86. case 3:
  87. p4();
  88. break;
  89. }
  90. glVertex2f(point[0],point[1]);
  91. }
  92. glEnd();
  93.  
  94.  
  95.  
  96. glFlush();
  97. }
  98.  
  99. void my_keyboard(unsigned char key, int x, int y){
  100. switch(key){
  101. case '+':
  102. if(points * 2 > 1000000)
  103. points = 1000000;
  104. else{
  105. points *= 2;
  106. }
  107. points *= 2;
  108. break;
  109. case '-':
  110. if(points > 1)points /= 2;;
  111. break;
  112. }
  113. render_scene();
  114.  
  115. }
  116. int main(int argc, char **argv) {
  117.  
  118. // init GLUT and create window
  119.  
  120. glutInit(&argc, argv);
  121. glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA);
  122. glutInitWindowSize(600,600);
  123. glutCreateWindow("Lighthouse3D - GLUT Tutorial");
  124. // register callbacks
  125. glutDisplayFunc(render_scene);
  126.  
  127. glutKeyboardFunc(my_keyboard);
  128.  
  129. // OpenGL init
  130. glEnable(GL_DEPTH_TEST);
  131. glMatrixMode(GL_MODELVIEW);
  132. glTranslated(-0.5,-1.0,0);
  133. glScalef(0.18,0.18,0.18);
  134. // enter GLUT event processing cycle
  135. glutMainLoop();
  136.  
  137. return 1;
  138. }
Add Comment
Please, Sign In to add comment