Advertisement
here2share

# Tk_wavy_grid_patterns.py

Jun 11th, 2019 (edited)
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. # Tk_wavy_grid_patterns.py
  2.  
  3. import math
  4. import time
  5. from tkinter import *
  6. import random
  7.  
  8. root = Tk()
  9. width,height=680,680
  10. root.geometry("%dx%d+-10+0"%(width,height))
  11. canvas = Canvas(root,width=width, height=height, background="yellow" )
  12. canvas.grid()
  13.  
  14. m = 10
  15. n = 10
  16. d = 20
  17. r = 20
  18. p = 60
  19. color = 'blue'
  20.  
  21. px = 50
  22. py = 50
  23.  
  24. k = 1
  25. angles = 360.0 / (m*n)
  26. spots = []
  27. for i in range(m):
  28.     for j in range(n):
  29.         x = px+(i*p)
  30.         y = py+(j*p)
  31.         spots += [[k,x,y]]
  32.         k += 1
  33. 0
  34. amount = len(spots)
  35. while 1:
  36.     canvas.delete('all')
  37.     for i in range(amount):
  38.         j,x,y = spots[i]
  39.         angle = j * angles
  40.         u = r * math.sin(angle*math.pi/180)
  41.         v = r * math.cos(angle*math.pi/180)
  42.         k = (j+1-(i*0.03))%amount
  43.         spots[i] = [k,x,y]
  44.         x += u
  45.         y += v
  46.         canvas.create_oval(x, y, x+d, y+d, fill=color, outline=color)
  47.     canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement