Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_blob.py
- from tkinter import *
- import math
- from random import shuffle, randint as rnd
- root = Tk()
- ww = 520
- hh = 520
- r = (min(ww,hh)-5)/2
- canvas = Canvas(root,width=ww,height=hh)
- canvas.pack()
- rainbow = []
- def rgb():
- rainbow.append('#{:02x}{:02x}{:02x}'.format(r,g,b))
- def wave(z,amp):
- return abs(amp-math.cos(math.radians(z))*amp)/2
- def wave_animate(amplitude):
- waves = {}
- for amp in range(3,amplitude+1):
- waves[amp] = []
- for z in range(0,3600,int(3600/(amp+30))):
- z *= 0.1
- zzz = int(wave(z,amp+1))
- if zzz == amp:
- waves[amp] += waves[amp][::-1][1:]
- break
- else:
- waves[amp] += [zzz+1]
- return waves
- WAVES = wave_animate(100)
- r, g, b = 255, 0, 0
- for g in range(256):
- rgb()
- for r in range(255, -1, -1):
- rgb()
- for b in range(256):
- rgb()
- for g in range(255, -1, -1):
- rgb()
- for r in range(256):
- rgb()
- for b in range(255, -1, -1):
- rgb()
- p = len(rainbow)/360.0
- r360 = [rainbow[int(z*p)] for z in range(360)]
- points = []
- circ = int((math.pi * r**2) / 500)
- p = 360.0/circ
- for z in range(0,ww,2):
- canvas.create_line((0,z,z+ww,z),fill='black')
- canvas.create_line((z,0,z,z+hh),fill='black')
- ANGLES = list(range(0,circ,3))
- def find_xy(t):
- t *= p
- wave = of_waves[int(t)]
- x = math.sin(math.radians(t))
- y = math.cos(math.radians(t))
- x,y = [z*(150+wave)+r-5 for z in (x,y)]
- return x,y
- while 1:
- of_circ = []
- of_waves = dict((z,[]) for z in range(circ+1))
- L = rnd(9,30)
- of_angles = ANGLES[:]
- shuffle(of_angles)
- while len(of_circ) < L+1:
- period = of_angles.pop()
- amp = rnd(10,30)
- of_circ.append((period,amp))
- for i in range(L):
- period,amp = of_circ[i]
- for j in WAVES[amp]:
- of_waves[period%(360+1)].append(j)
- period += 1
- of_waves = [sum(of_waves[z]) for z in range(circ)]
- canvas.delete('blob')
- px,py = find_xy(0)
- x0,y0 = px,py
- for t in range(1,circ):
- x,y = find_xy(t)
- # angle = math.degrees(math.atan2(x,y))
- color = r360[int(t*p)]
- canvas.create_line((px,py,x,y),fill=color,width=5,tag='blob')
- px,py = x,y
- color = r360[int(t*p)]
- canvas.create_line((x,y,x0,y0),fill=color,width=5,tag='blob')
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement