Advertisement
here2share

# Tk_line_rotate_patterns.py

Dec 4th, 2020 (edited)
1,339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. # Tk_line_rotate_patterns.py
  2.  
  3. from math import cos,sin,pi,radians
  4. import random
  5.  
  6. r=random.randint
  7.  
  8. try:
  9.     import tkinter as tk
  10. except:
  11.     import Tkinter as tk
  12.  
  13. root=tk.Tk()  
  14. root.title("Tk Line Rotate Patterns")
  15.  
  16. ww=640
  17. hh=640
  18.  
  19. mid=(ww+hh)/4
  20.  
  21. canvas=tk.Canvas(root,width=ww,height=hh)
  22. canvas.pack(fill="both",expand=True)
  23.  
  24.  
  25. class Cv(): 0
  26. cv=Cv()
  27. cv.color='red'
  28. COLORS = 'red darkorange yellow green blue purple'.split()
  29. cv.a=1
  30. cv.b=1
  31. cv.a2=1
  32. cv.b2=1
  33. cv.o360=360
  34. cv.angle2=0
  35. cv.count=0
  36.  
  37. STEP=25
  38.  
  39. def mark():
  40.     a=cv.a*STEP
  41.     b=a+(cv.b*STEP)
  42.     c=int(360.0/cv.o360)
  43.     for angle in range(0,360,c):
  44.         x0=mid+cos(radians(angle))*a
  45.         y0=mid+sin(radians(angle))*a
  46.        
  47.         angle=(angle+cv.angle2)%360
  48.         x1=mid+cos(radians(angle))*b
  49.         y1=mid+sin(radians(angle))*b
  50.        
  51.         canvas.create_line(x0,y0,x1,y1,width=2,fill=cv.color)
  52.  
  53. def tick():
  54.     canvas.delete(tk.ALL)
  55.     random.shuffle(COLORS)
  56.     colors2 = COLORS[:]
  57.    
  58.     for z in range(3):
  59.         cv.b=r(1,15)
  60.         cv.a=r(1,16-cv.b)
  61.         cv.angle2=r(0,360)
  62.         cv.o360=r(3,50)
  63.         cv.color=colors2.pop()
  64.         mark()
  65.     canvas.after(500,tick)
  66.  
  67. tick()
  68.  
  69. tk.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement