Advertisement
here2share

# Tk_star_pattern.py

May 22nd, 2019
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. # Tk_star_pattern.py
  2.  
  3. from Tkinter import *
  4. import math
  5. import random
  6. import time
  7.  
  8. root = Tk()
  9.  
  10. c_width = 600
  11. c_height = 600
  12. canvas = Canvas(root, width=c_width, height=c_height, bg='white')
  13. canvas.pack()
  14. starXY = [c_width/2,c_height/2]
  15.  
  16. def star_pattern(points, innerRadius, outerRadius):
  17.     points *= 2
  18.     segments = (math.pi * 2.0) / points
  19.     radiusChoice = [innerRadius, outerRadius]
  20.     star = []
  21.     switch = [0,1]
  22.     for point in range(points):
  23.         r = radiusChoice[switch[-1]]
  24.         omega = segments * point
  25.         star.append(((r * -math.sin(omega)) + starXY[0], (r * -math.cos(omega)) + starXY[1]))
  26.         switch += [switch.pop(0)]
  27.     return star
  28.  
  29. wait = 0
  30. while 1:
  31.     outer = 270
  32.     color = '#%02x%02x%02x' % (180, 0, 180)
  33.     for points in range(3,30):
  34.         for inner in range(20,min(240,100+points*3)):
  35.             canvas.create_polygon(star_pattern(points,inner,outer), fill=color)
  36.             #time.sleep(0.2)
  37.             canvas.update()
  38.             canvas.delete('all')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement