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

Mandelbrot Set Fractal (See related posts)

I take the code from Gustavo Niemeyer and modify it a bit.
import e32
from appuifw import *

app.screen = 'full'
app.body = canvas = Canvas()
width, height = canvas.size

xaxis = width/2
yaxis = height/1.5
scale = 60
iterations = 25

for y in range(height):
  for x in range(width):
    magnitude = 0
    z = 0+0j
    c = complex(float(y-yaxis)/scale, float(x-xaxis)/scale)
    for i in range(iterations):
      z = z**2+c
      if abs(z) > 2:
        v = 765*i/iterations
        if v > 510:
          color = (255, 255, v%255)
        elif v > 255:
          color = (255, v%255, 0)
        else:
          color = (v%255, 0, 0)
        break
    else:
      color = (0, 0, 0)
    canvas.point((x, y), color)
  e32.ao_yield()
 
lock = e32.Ao_lock()
app.exit_key_handler = lock.signal
lock.wait()

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


Click here to browse all 5147 code snippets

Related Posts