I started coding a little app for exploring the mandelbrot fractal. Hopefully someone here is familiar with it, and perhaps tried coding it in python.
My problem is, as you will see if you try running my code, is that the generated image is NOT the mandelbrot (although it is fractal and similar in a sense). And I just cant figure out why this is. So my hopes are that this is due to some oddity of python I am hitherto unaware of - I can't see any misstakes in the algorithm itself (although it might be there anyway of course :) )
heres the code (uses pygame and numeric, and is in no way optimized - I wanted it that way to make sure no mistakes were made)
import pygame from Numeric import * from pygame import * pygame.init() WHITE=(255,255,255,255) BLACK=(0,0,0,255) WIDTH=200 HEIGHT=200 ITERATIONS = 20 rmin=-1.0 rmax=2.0 imin=-2.0 imax=2.0 canvas=pygame.display.set_mode((WIDTH,HEIGHT)) canvas.fill(BLACK) pygame.display.update() px=-1 for a in arange(rmin,rmax,(rmax-rmin)/WIDTH): px+=1 py=-1 for b in arange(imax,imin,(imin-imax)/HEIGHT): py+=1 x = 0 y = 0 i=0 while i<ITERATIONS and (x*x+y*y)<4: x=x*x-y*y+a y=2*x*y +b i=i+1 if i==ITERATIONS: canvas.set_at((px,py),WHITE) else: canvas.set_at((px,py),BLACK) pygame.display.update() pygame.time.wait(2000)