Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_Spectral_Harmonograph.py
- from math import sin,pi
- import random as r
- from colorsys import hsv_to_rgb
- try:
- import tkinter as tk
- except:
- import Tkinter as tk
- root=tk.Tk()
- root.title("Tk Spectral Harmonograph")
- ww,hh=1280,720
- canvas=tk.Canvas(root,width=ww,height=hh)
- canvas.pack(fill="both",expand=True)
- gap=100
- ww-=gap
- hh-=gap
- depth=ww
- hui=.159
- dec=0.999999
- dt=0.01
- mx=10
- sd=0.002
- def scale(length):
- while True:
- a1,a2=r.randint(-mx,mx),r.randint(-mx,mx)
- max=abs(a1)+abs(a2)
- if max>0: break
- return a1,a2,length/(2*max)
- def hsv2rgb(*hsv):
- rgb = hsv_to_rgb(*hsv)
- r = hex(int(rgb[0]*255))[2:]
- if len(r) < 2:
- r = "0"+r
- g = hex(int(rgb[1]*255))[2:]
- if len(g) < 2:
- g = "0"+g
- b = hex(int(rgb[2]*255))[2:]
- if len(b) < 2:
- b = "0"+b
- hexCode = "#" + r + g + b
- # hsv[0]+=0.01
- return hexCode
- while True:
- trail=[]
- ax1,ax2,xscale=scale(ww)
- ay1,ay2,yscale=scale(hh)
- # az1,az2,zscale=scale(depth)
- fx1, fx2 = r.randint(1,mx) + r.gauss(0,sd), r.randint(1,mx) + r.gauss(0,sd)
- fy1, fy2 = r.randint(1,mx) + r.gauss(0,sd), r.randint(1,mx) + r.gauss(0,sd)
- # fz1, fz2 = r.randint(1,mx) + r.gauss(0,sd), r.randint(1,mx) + r.gauss(0,sd)
- px1, px2 = r.uniform(0,2*pi), r.uniform(0,2*pi)
- py1, py2 = r.uniform(0,2*pi), r.uniform(0,2*pi)
- # pz1, pz2 = r.uniform(0,2*pi), r.uniform(0,2*pi)
- x=y=z=0.0
- k=1
- hue=0
- t=0
- trail=[(x,y,z,hsv2rgb(hue,1,1))]
- for j in range (50):
- for i in range (2000):
- x = xscale * k * (ax1*sin(t * fx1 + px1) + ax2*sin(t * fx2 + px2))
- y = yscale * k * (ay1*sin(t * fy1 + py1) + ay2*sin(t * fy2 + py2))
- # z = zscale * k * (az1*sin(t * fz1 + pz1) + az2*sin(t * fz2 + pz2))
- x+=ww/2
- y+=hh/2
- trail.append((x,y,z,hsv2rgb(hue,1,1)))
- hue = (hue + dt*hui) % 360
- t+=dt
- k*=dec
- canvas.delete('all')
- for x,y,z,color in trail:
- canvas.create_oval((x,y,x+1,y+1),fill=color)
- root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement