Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_smooth_wave_fn.py
- from tkinter import *
- import random
- import math
- import time
- root = Tk()
- root.title("Smooth Wave Algorithm")
- ww = 1400
- hh = 300
- cy = hh//2-128
- root.geometry("%dx%d+-10+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.pack()
- waves = {}
- steps = 10
- for i in range(256):
- for j in range(256):
- values = []
- j2 = min(i+50, min(i-50, j))
- for step in range(1,steps+1):
- value = i + (j-i) * step/steps * 0.5
- values.append(value)
- waves[(i,j)] = values
- while True:
- canvas.delete('all')
- data =[random.randint(0,255) for _ in range(0, ww, steps)]
- L= ww // steps -1
- x=0
- y0=random.randint(0 ,255)
- for j in range(L):
- target=max(0,min(255,y0+random.randint(-20 ,20)))
- for i in range(steps):
- y=waves[int(y0),int(target)][i]
- canvas.create_line(x,cy+y0,x+1,cy+y ,fill='green')
- y0=y
- x+=1
- canvas.update()
- time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement