Advertisement
here2share

# quantum_cubes.py

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