Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_line_rotate_patterns.py
- from math import cos,sin,pi,radians
- import random
- r=random.randint
- try:
- import tkinter as tk
- except:
- import Tkinter as tk
- root=tk.Tk()
- root.title("Tk Line Rotate Patterns")
- ww=640
- hh=640
- mid=(ww+hh)/4
- canvas=tk.Canvas(root,width=ww,height=hh)
- canvas.pack(fill="both",expand=True)
- class Cv(): 0
- cv=Cv()
- cv.color='red'
- COLORS = 'red darkorange yellow green blue purple'.split()
- cv.a=1
- cv.b=1
- cv.a2=1
- cv.b2=1
- cv.o360=360
- cv.angle2=0
- cv.count=0
- STEP=25
- def mark():
- a=cv.a*STEP
- b=a+(cv.b*STEP)
- c=int(360.0/cv.o360)
- for angle in range(0,360,c):
- x0=mid+cos(radians(angle))*a
- y0=mid+sin(radians(angle))*a
- angle=(angle+cv.angle2)%360
- x1=mid+cos(radians(angle))*b
- y1=mid+sin(radians(angle))*b
- canvas.create_line(x0,y0,x1,y1,width=2,fill=cv.color)
- def tick():
- canvas.delete(tk.ALL)
- random.shuffle(COLORS)
- colors2 = COLORS[:]
- for z in range(3):
- cv.b=r(1,15)
- cv.a=r(1,16-cv.b)
- cv.angle2=r(0,360)
- cv.o360=r(3,50)
- cv.color=colors2.pop()
- mark()
- canvas.after(500,tick)
- tick()
- tk.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement