Advertisement
here2share

# quantum_cubes_2.py

Apr 25th, 2021
1,243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. # quantum_cubes_2.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. for yc in range(-base,hh,int(base*1.5)):
  36.     for xc in range(-b2+(b3*(c%2)),ww+b2,b2):
  37.         points += [(xc,yc)]
  38.         points += [(xc+b2,yc+base)]
  39.     c+=1
  40.  
  41. while 1:
  42.     xc,yc = choice(points)
  43.     t = str([xc,yc])
  44.     try:
  45.         for k in ('red','green','blue'):
  46.             canvas.delete(cubes[t][k])
  47.         del cubes[t]
  48.     except:
  49.         cubes[t] = {}
  50.         angle=0
  51.         color='red'
  52.         create_tile()
  53.         angle=120
  54.         color='green'
  55.         create_tile()
  56.         angle=240
  57.         color='blue'
  58.         create_tile()
  59.         canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement