Advertisement
here2share

# quantum_cubes_4.py

Apr 26th, 2021
757
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_4.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] = 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. sides = [
  41.         ('red',0),
  42.         ('green',120),
  43.         ('blue',240),
  44.         ]
  45.  
  46. for yc in range(-base,hh,int(base*1.5)):
  47.     for xc in range(-b2+(b3*(c%2)),ww+b2,b2):
  48.         points += [(xc,yc)]
  49.         c2+=1
  50.     c+=1
  51.  
  52. while 1:
  53.     xc,yc = choice(points)
  54.     color, angle = choice(sides)
  55.     t = str([xc,yc,color])
  56.     try:
  57.         canvas.delete(cubes[t])
  58.         del cubes[t]
  59.     except:
  60.         color, angle = choice(sides)
  61.         create_tile()
  62.         canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement