Advertisement
here2share

# quantum_cubes_5.py

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