animation.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. import pygame
  2. import pygame.gfxdraw
  3. import math
  4. pg = pygame
  5. pygame.init()
  6. #window = pygame.display.set_mode((600, 300))#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  7. window = pygame.display.set_mode((600, 300),pg.RESIZABLE,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  8. #window = pygame.display.set_mode((600, 300),pg.NOFRAME,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  9. #window = pygame.display.set_mode((1600, 900),pg.NOFRAME,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  10. #window = pygame.display.set_mode((600, 300),pygame.FULLSCREEN) #x left->right ,y top-> bottom
  11. # pygame.display.set_mode((self.width, int(self.height+(self.height*0.15))) ,pygame.FULLSCREEN)
  12. pg.display.set_caption('LibreLight Animation')
  13. def event_read():
  14. inc = 1
  15. for event in pg.event.get():
  16. print("event",event)
  17. move_x = 0
  18. move_y = 0
  19. move_z = 0
  20. rot_x = 0
  21. rot_y = 0
  22. rot_z = 0
  23. if event.type== pg.QUIT:
  24. print("quit")
  25. pg.quit()
  26. quit()
  27. sys.exit()
  28. if "key" in dir(event):
  29. if event.key == 27: #ESC pg.KEYDOWN:
  30. print("quit")
  31. pg.quit()
  32. quit()
  33. sys.exit()
  34. class Grid():
  35. def __init__(self):
  36. pixA = []
  37. for c in range(10):
  38. row = []
  39. for r in range(10):
  40. color = [r,r,r]
  41. row.append(color)
  42. pixA.append(row)
  43. self.pixA = pixA
  44. self.red = 0
  45. self.green = 0
  46. self.blue = 0
  47. self.blue_dir = 1
  48. def draw(self):
  49. pixA = self.pixA
  50. #pixel_array = pygame.PixelArray(window)
  51. pixel_array = {} # pygame.PixelArray(window)
  52. #pixel_array.open()
  53. a_x_max = 600 #pixel_array[0])
  54. a_y_max = 300 #pixel_array)
  55. b_x_max = len(pixA[0])
  56. b_y_max = len(pixA)
  57. b_h = int(a_x_max / b_x_max)
  58. b_w = int(a_y_max / b_y_max)
  59. self.red = 0
  60. self.green = 0
  61. #blue = 255
  62. for r,row in enumerate(pixA):
  63. self.red += 30
  64. if self.red > 255:
  65. self.red = 255
  66. self.green = 0
  67. if self.blue > 255:
  68. self.blue = 255
  69. self.blue_dir = 0
  70. if self.blue <= 0:
  71. self.blue = 0
  72. self.blue_dir = 1
  73. for c,col in enumerate(row):
  74. self.green += 30
  75. if self.green > 255:
  76. self.green = 255
  77. color = pygame.Color(self.red,self.green,self.blue)
  78. #print("x:{:3} y:{:3} {:3} {:3} c:{}".format(x,y,x+bc,y+br,color))
  79. x = r*b_w
  80. y = c*b_h
  81. #pixel_array[r*b_w][c*b_h] = color
  82. #pixel_array[x:x+b_w-1,y:y+b_h-1] = color
  83. k = "{}:{},{}:{} {}".format(x,x+b_w-1,y,y+b_h-1,color) #x,x+10,y,y+10)
  84. pixel_array[k] = (x,x+b_w-1,y,y+b_h-1,color)
  85. #pixel_array.close()
  86. #one = 0
  87. if self.blue_dir:
  88. self.blue += 10
  89. else:
  90. self.blue -= 10
  91. return pixel_array
  92. class _planet():
  93. def __init__(self,x,y):
  94. self._pos_center = (x,y)
  95. self._ang = 0
  96. self._r = 10 #
  97. self._r2 = 10 # orbit,umlaufbahn
  98. self._color = [255,255,255]
  99. self._x=0
  100. self._y=0
  101. self.ix = math.sin(math.radians(0))*self.r
  102. self.iy = math.sqrt(self.r**2 - ix**2)
  103. def ang(self):
  104. pass
  105. def draw():
  106. pass
  107. return (self._x,self._y,self._color)
  108. class Gobo1():
  109. def __init__(self,x=20,y=20,speed=5):
  110. self.pos_x=x
  111. self.pos_x_dir = 1
  112. self.pos_y=y
  113. self.pos_y_dir = 1
  114. self.r = 7
  115. self.r_dir = 1
  116. self.speed = speed
  117. self.ang = 0
  118. self.ix=0
  119. self.iy=0
  120. def rotate(self):
  121. self.ix = math.sin(math.radians(0))*self.r
  122. self.iy = math.sqrt(self.r**2 - self.ix**2)
  123. self.ang+=1
  124. if self.ang >= 360:
  125. self.ang = 0
  126. def draw(self,color=[255,255,255]):
  127. self.rotate()
  128. #pixel_array = pygame.PixelArray(window)
  129. pixel_array = {}
  130. self.color = pygame.Color(color[0],color[1],color[2])
  131. x=self.pos_x
  132. y=self.pos_y
  133. x-=self.r
  134. y-=self.r
  135. k = "{}:{},{}:{}".format(x,x+10,y,y+10)
  136. pixel_array[k] = (x,x+10,y,y+10 , self.color )
  137. x+=self.r*2
  138. k = "{}:{},{}:{}".format(x,x+10,y,y+10)
  139. pixel_array[k] = (x,x+10,y,y+10 , self.color )
  140. y+=self.r*2
  141. x-=self.r
  142. k = "{}:{},{}:{}".format(x,x+10,y,y+10)
  143. pixel_array[k] = (x,x+10,y,y+10 , self.color )
  144. #pixel_array.close()
  145. if self.pos_x > 300:
  146. self.pos_x_dir = 0
  147. if self.pos_x <= self.speed:
  148. self.pos_x_dir = 1
  149. if self.pos_x_dir:
  150. self.pos_x += self.speed
  151. else:
  152. self.pos_x -= self.speed
  153. if self.r > 20:
  154. self.r_dir = 0
  155. if self.r <=7:
  156. self.r_dir = 1
  157. if self.r_dir:
  158. self.r+=1
  159. else:
  160. self.r-=1
  161. return pixel_array
  162. run = True
  163. one = 1
  164. blue = 0
  165. blue_dir = 1
  166. pos_x_dir = 1
  167. #pixel_array = pygame.PixelArray(window)
  168. import time
  169. #time.sleep(1)
  170. grid = Grid()
  171. gobo1 = Gobo1()
  172. gobo2 = Gobo1(200,150,speed=8)
  173. while run:
  174. event_read()
  175. if one:
  176. window.fill(0)
  177. d=grid.draw()
  178. d1=gobo1.draw()#20,10)
  179. d2=gobo2.draw()#20,10)
  180. pixel_array = pygame.PixelArray(window)
  181. for k in d:
  182. i = d[k]
  183. print( k,"i",i)
  184. #pixel_array[i[0]:i[1],i[2]:i[3]] = i[4] #(x,x+10,y,y+10 , self.color )
  185. #rect = pygame.Rect(window.get_rect().center, (10, 10)) #.inflate(*([min(window.get_size())//2]*2))
  186. #rect = pygame.draw.circle(window,pg.Color(200,0,200) , (10,10) ,10)
  187. rect = pygame.draw.circle(window,i[4] , (i[0]+10,i[2]) ,10)
  188. rect = pygame.gfxdraw.aacircle(window, i[0]+10,i[2] ,10,i[4])
  189. #rect = pygame.draw.Rect(window,i[4] , (i[0],i[2]) ,10) #(10, 10))
  190. #rect = pygame.Rect(window.get_rect().center, (0, 0)).inflate(*([min(window.get_size())//2]*2))
  191. #pygame.display.flip()
  192. for k in d1:
  193. i = d1[k]
  194. print( k,"i",i)
  195. #pixel_array[i[0]:i[1],i[2]:i[3]] = i[4] #(x,x+10,y,y+10 , self.color )
  196. rect = pygame.draw.circle(window,i[4] , (i[0]+10,i[2]) ,10)
  197. rect = pygame.gfxdraw.aacircle(window, i[0]+10,i[2] ,10,i[4])
  198. for k in d2:
  199. i = d2[k]
  200. print( k,"i",i)
  201. #pixel_array[i[0]:i[1],i[2]:i[3]] = i[4] #(x,x+10,y,y+10 , self.color )
  202. rect = pygame.draw.circle(window,i[4] , (i[0]+10,i[2]) ,10)
  203. rect = pygame.gfxdraw.aacircle(window, i[0]+10,i[2] ,10,i[4])
  204. pixel_array.close()
  205. #pygame.display.flip()
  206. #gobo2.draw(color=[255,0,0])
  207. #pygame.display.flip()
  208. pg.time.wait(10)
  209. pygame.display.flip()
  210. pg.time.wait(10)
  211. pygame.quit()
  212. exit()