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)
- y = hh/2
- amp = 10
- vel = 0.0 # velocity
- smoothness = 100.0
- def init():
- global x, y, vel
- canvas.delete('all')
- ttt = []
- x = 0
- while x < ww:
- aim = max(amp*2,min(hh-amp*2,y+random.randint(-amp,amp)))
- ttt += [aim]
- for x2 in range(0,10):
- vel += (aim-y)/smoothness
- y += vel
- plot()
- x += 1
- if x > ww:
- break
- root.after(1000,init)
- init()
- root.mainloop()
Advertisement
Advertisement