Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # quantum_cubes_3.py
- from Tkinter import *
- from random import *
- from math import cos, sin, radians
- ww = 720
- hh = 720
- tiles = (0.0, 0.0), (-0.866, -0.5), (0.0, -1.0), (0.866, -0.5)
- def create_tile():
- polygon = [(x*base, y*base) for (x,y) in tiles]
- polygon = [( xc+x*cos(radians(angle)) + y*sin(radians(angle)),
- yc+y*cos(radians(angle)) - x*sin(radians(angle)) )
- for (x,y) in polygon]
- cubes[t][color] = canvas.create_polygon(polygon, fill=color, outline="black", width=1)
- root = Tk()
- canvas = Canvas(root, width=ww, height=hh)
- canvas.pack(fill=BOTH)
- xc=360
- yc=360
- base=25
- b2=int(0.866*2*base)
- b3=b2/2
- cubes = {}
- points = []
- c=0
- c2=0
- t = 'bg'
- cubes[t] = {}
- for yc in range(-base,hh,int(base*1.5)):
- for xc in range(-b2+(b3*(c%2)),ww+b2,b2):
- angle=0
- color='red'
- create_tile()
- angle=120
- color='green'
- create_tile()
- angle=240
- color='blue'
- create_tile()
- #if c2%2 and c%2:
- points += [(xc,yc+base*2)]
- c2+=1
- c+=1
- while 1:
- xc,yc = choice(points)
- t = str([xc,yc])
- try:
- for k in ('red','green','blue'):
- canvas.delete(cubes[t][k])
- del cubes[t]
- except:
- cubes[t] = {}
- angle=0
- color='red'
- create_tile()
- angle=120
- color='green'
- create_tile()
- angle=240
- color='blue'
- create_tile()
- canvas.update()
Add Comment
Please, Sign In to add comment