Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_1D_Curvy_Waves.py
- '''
- create curvy waves
- '''
- from tkinter import *
- import PIL
- import math
- import random
- ww = 1400
- hh = 600
- root=Tk()
- root.geometry("%dx%d+-10+0"%(ww,hh))
- canvas = Canvas(root,width=ww,height=hh,bg='black')
- canvas.grid(row=0,column=0,sticky=N+S+E+W)
- def oRGB(rgb):
- r,g,b = rgb
- return "#%02x%02x%02x" % (r,g,b)
- def plot():
- canvas.create_line((x, 0, x, y), fill=color)
- rgb = 255,255,0 # yellow
- color = oRGB(rgb)
- red = oRGB((255,0,0))
- y = hh/2
- steps = 20
- vel = 0.0 # velocity
- def targets(ttt): # display last
- for x1,aim in enumerate(ttt):
- x1 = x1 * steps
- canvas.create_line((x1+steps*0.5, aim, x1+steps*1.5, aim), fill=red)
- def init():
- global x, y, vel
- canvas.delete('all')
- ttt = []
- for x1 in range(0,ww,steps):
- aim = max(20,min(hh-20,y+random.randint(-20,20)))
- ttt += [aim]
- for x2 in range(0,steps):
- x = x1+x2
- vel += (aim-y)/120.0
- y += vel
- plot(x)
- # targets(ttt)
- root.after(1000,init)
- init()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement