here2share

# quantum_cubes_3.py

Apr 25th, 2021 (edited)
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. # quantum_cubes_3.py
  2.  
  3. from Tkinter import *
  4. from random import *
  5. from math import cos, sin, radians
  6.  
  7. ww = 720
  8. hh = 720
  9.  
  10. tiles = (0.0, 0.0), (-0.866, -0.5), (0.0, -1.0), (0.866, -0.5)
  11.  
  12. def create_tile():
  13.     polygon = [(x*base, y*base) for (x,y) in tiles]
  14.  
  15.     polygon = [(    xc+x*cos(radians(angle)) + y*sin(radians(angle)),
  16.                     yc+y*cos(radians(angle)) - x*sin(radians(angle)) )
  17.                     for (x,y) in polygon]
  18.  
  19.     cubes[t][color] = canvas.create_polygon(polygon, fill=color, outline="black", width=1)
  20.  
  21. root = Tk()
  22.  
  23. canvas = Canvas(root, width=ww, height=hh)
  24. canvas.pack(fill=BOTH)
  25.  
  26. xc=360
  27. yc=360
  28. base=25
  29. b2=int(0.866*2*base)
  30. b3=b2/2
  31.  
  32. cubes = {}
  33. points = []
  34. c=0
  35. c2=0
  36.  
  37. t = 'bg'
  38. cubes[t] = {}
  39.  
  40. for yc in range(-base,hh,int(base*1.5)):
  41.     for xc in range(-b2+(b3*(c%2)),ww+b2,b2):
  42.         angle=0
  43.         color='red'
  44.         create_tile()
  45.         angle=120
  46.         color='green'
  47.         create_tile()
  48.         angle=240
  49.         color='blue'
  50.         create_tile()
  51.         #if c2%2 and c%2:
  52.         points += [(xc,yc+base*2)]
  53.         c2+=1
  54.     c+=1
  55.  
  56. while 1:
  57.     xc,yc = choice(points)
  58.     t = str([xc,yc])
  59.     try:
  60.         for k in ('red','green','blue'):
  61.             canvas.delete(cubes[t][k])
  62.         del cubes[t]
  63.     except:
  64.         cubes[t] = {}
  65.         angle=0
  66.         color='red'
  67.         create_tile()
  68.         angle=120
  69.         color='green'
  70.         create_tile()
  71.         angle=240
  72.         color='blue'
  73.         create_tile()
  74.         canvas.update()
Add Comment
Please, Sign In to add comment