Never been to DZone Snippets before?

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 (See related posts)

A nice visualization from Simon Wittber's recipe
   1  
   2  from appuifw import *
   3  import e32, random
   4  from math import *
   5  
   6  app.body = c = Canvas()
   7  width, height =  c.size
   8  freq = random.choice([25., 50., 100., 200., 400.])
   9  
  10  for y in range(height):
  11      for x in range(width):
  12          z1 = sin(x/freq*1.7*pi)
  13          z2 = sin((x/3+y)/freq*1.5*pi)
  14          z3 = sin(y/freq*0.1*pi)
  15  
  16          z = abs(z1+z2+z3)*255
  17          c.point((x,y), (z,z/4,z*4))
  18  c.text((5, height-12), u'Freq = %d' %freq, 0xffffff)
  19  
  20  e32.ao_sleep(5)    # wait 5 sec then quit

See a screenshot here.

You need to create an account or log in to post comments to this site.


Click here to browse all 5551 code snippets

Related Posts