DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Sine Wave Interference Patterns
A nice visualization from Simon Wittber's <a href=http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/334696>recipe</a>
from appuifw import *
import e32, random
from math import *
app.body = c = Canvas()
width, height = c.size
freq = random.choice([25., 50., 100., 200., 400.])
for y in range(height):
for x in range(width):
z1 = sin(x/freq*1.7*pi)
z2 = sin((x/3+y)/freq*1.5*pi)
z3 = sin(y/freq*0.1*pi)
z = abs(z1+z2+z3)*255
c.point((x,y), (z,z/4,z*4))
c.text((5, height-12), u'Freq = %d' %freq, 0xffffff)
e32.ao_sleep(5) # wait 5 sec then quit
See a screenshot <a href=http://www.flickr.com/photos/korakot/43547841/>here</a>.




