Over a million developers have joined DZone.

Sine Wave Interference Patterns

·
A nice visualization from Simon Wittber's recipe

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 here.
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}