Advertisement
here2share

# Tk_central_pop_art.py

Dec 5th, 2020
1,130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. # Tk_central_pop_art.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 Central Pop Art")
  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=''
  28. COLORS = 'red darkorange yellow green blue purple'.split()
  29. cv.x=0
  30. cv.y=0
  31. cv.a=1
  32. cv.b=1
  33. cv.a2=1
  34. cv.b2=1
  35. cv.o360=360
  36. cv.angle2=0
  37. cv.start=0
  38. cv.count=0
  39.  
  40. STEP=25
  41.  
  42. def mark():
  43.     a=cv.a*STEP
  44.     b=a+(cv.b*STEP)
  45.     c=360.0/cv.o360
  46.     angle = cv.start
  47.     for null in range(0,360,int(c)):
  48.         angle += c
  49.         angle = angle%360
  50.         x0=cv.x+cos(radians(angle))*a
  51.         y0=cv.y+sin(radians(angle))*a
  52.        
  53.         x1=cv.x+cos(radians(angle))*b
  54.         y1=cv.y+sin(radians(angle))*b
  55.        
  56.         canvas.create_line(x0,y0,x1,y1,width=5,fill=cv.color)
  57.  
  58. def tick():
  59.     #canvas.delete(tk.ALL)
  60.     c2s = r(5,60)
  61.     cv.x,cv.y=[r(0,640) for z in 'zz']
  62.     cv.b=r(1,15)
  63.     cv.a=r(1,16-cv.b)
  64.     cv.angle2=r(0,360)
  65.     cv.start=r(0,360)
  66.     cv.o360=c2s
  67.     try:
  68.         cv.color=cv.colors2.pop()
  69.     except:
  70.         cv.colors2 = COLORS[:]
  71.         cv.color=cv.colors2.pop()
  72.     mark()
  73.     canvas.after(1,tick)
  74.  
  75. tick()
  76.  
  77. tk.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement