Guest User

Untitled

a guest
Jul 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. from math import *
  4. from pyglet.gl import *
  5. from pyglet import clock
  6. from pyglet.clock import *
  7.  
  8. x = y = []
  9. curCoordPos = 0
  10. SCREEN_WIDTH = 800
  11. SCREEN_HEIGHT = 600
  12. POINTS_NUM = 100
  13. CURVES_NUM = 30
  14. flag = a = 0
  15.  
  16.  
  17. def init_coord():
  18. i = a = 0
  19. global flag
  20.  
  21. for i in xrange(CURVES_NUM):
  22. for j in xrange(POINTS_NUM):
  23. if flag == 0:
  24. rx = ((100 + 4 * i) * cos(a + 0.174))
  25. ry = ((100 + 4 * i) * sin(a))
  26. elif flag == 1:
  27. rx = (380 - i * 5) * sin(a + 0.2)
  28. ry = i * 8 * sin(a / 2) * cos(a) * cos(a)
  29. elif flag == 2:
  30. rx = (14 * (i - 16) * cos(a) + 5 * i) * sin(a + 0.2)
  31. ry = (9 * (i - 16) * sin(a) + 5 * i) * cos(a)
  32. elif flag == 3:
  33. rx = 20 * i * sin(a) * cos(a) * sin(a + 0.2)
  34. ry = (100 - 18 * i * sin(a) * cos(a * 2)) * cos(a)
  35. elif flag == 4:
  36. rx = (100 + 4 * i) * cos(a * 2 + 0.174)
  37. ry = ((100 + 4 * i) * sin(a))
  38. elif flag == 5:
  39. rx = (100 + 4 * i) * cos(a * 2 + 0.174)
  40. ry = ((100 + 4 * i) * cos(a + 0.174 * (i / 3)))
  41. x[i].append(400 + rx) #400 - SCREEN_WIDTH / 2
  42. y[i].append(300 + ry) #300 - SCREEN_HEIGHT / 2
  43. a += ((2 * pi) / POINTS_NUM)
  44.  
  45. def dec_coord_cos():
  46. global curCoordPos
  47. curCoordPos -= 1;
  48. if(curCoordPos < 0):
  49. curCoordPos = POINTS_NUM - 1
  50.  
  51. def draw():
  52. k=1
  53. glLoadIdentity()
  54. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  55. glBegin(GL_POINTS)
  56. for i in xrange(CURVES_NUM):
  57. for j in xrange(POINTS_NUM):
  58. glColor3f(k*i%1, 1 - k*j*i, k*j%1)
  59. glVertex2f((x[i][curCoordPos]), (y[i][j]))
  60. dec_coord_cos()
  61. if k>0:
  62. k -= 0.01
  63. else:
  64. k=1
  65. glEnd()
  66. dec_coord_cos()
  67.  
  68. def reset():
  69. global x, y
  70. x = []
  71. y = []
  72. for i in xrange(CURVES_NUM):
  73. x.append([])
  74. y.append([])
  75.  
  76. def main_loop(dt):
  77. init_coord()
  78. draw()
  79.  
  80. window = pyglet.window.Window()
  81. window.set_size(SCREEN_WIDTH, SCREEN_HEIGHT)
  82. glEnable(GL_TEXTURE_2D)
  83.  
  84. glClearColor(0.0, 0.0, 0.0, 0.0)
  85. reset()
  86.  
  87. schedule_interval(main_loop, .03)
  88.  
  89. @window.event
  90. def on_mouse_scroll(x, y, scx, scy):
  91. global flag
  92. reset()
  93. flag = (flag + 1) % 6
  94.  
  95. pyglet.app.run()
Add Comment
Please, Sign In to add comment