I have created a Python file to generate a Mandelbrot set image. The original maths code was not mine, so I do not understand it – I only heavily modified it to make it about 250x faster (Threads rule!).
Anyway, I was wondering how I could modify the maths part of the code to make it render one specific bit. Here is the maths part:
for y in xrange(size[1]): coords = (uleft[0] + (x/size[0]) * (xwidth),uleft[1] - (y/size[1]) * (ywidth)) z = complex(coords[0],coords[1]) o = complex(0,0) dotcolor = 0 # default, convergent for trials in xrange(n): if abs(o) <= 2.0: o = o**2 + z else: dotcolor = trials break # diverged im.putpixel((x,y),dotcolor)
And the size definitions:
size1 = 500 size2 = 500 n=64 box=((-2,1.25),(0.5,-1.25)) plus = size[1]+size[0] uleft = box[0] lright = box[1] xwidth = lright[0] - uleft[0] ywidth = uleft[1] - lright[1]
what do I need to modify to make it render a certain section of the set?
The line:
is the bit that defines the area of coordinate space that is being rendered, so you just need to change this line. First coordinate pair is the top-left of the area, the second is the bottom right.
To get a new coordinate from the image should be quite straightforward. You’ve got two coordinate systems, your ‘image’ system 100×100 pixels in size, origin at (0,0). And your ‘complex’ plane coordinate system defined by ‘box’. For X: