1

This Mandelbrot set I created works well although I don't know how to colour like other ones on places like Wikipedia. My version is just plain yellow (see below).

from graphics import *

zoom = 0.1
xOffset = -0.171
yOffset = 0.61

def mandelbrot(spacing, maxIterations, width, height):
    win = GraphWin("Mandelbrot",width,height)
    win.setBackground('black')

    for x in range(0,width,spacing):
        for y in range(0,height,spacing):
            a = ((x / width) * zoom) - xOffset
            b = ((y / height) * zoom) - yOffset
            pt = Point(x,y)
            n = 0
            coordA = a
            coordB = b
            while(n<maxIterations):
                aa = a * a - b * b
                bb = 2 * a * b
                a = aa + coordA
                b = bb + coordB
                n+=1
                colourR = int(round(n/maxIterations * 255))
                colourB = 255-colourR
                if(abs(a+b) > 2):
                    break


            pt.setFill(color_rgb(colourR, colourR, 0))
            pt.draw(win)

mandelbrot(1,2000,700,700)

Image:

Mandelbrot set image

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    How do you want it to be? – Alfabravo May 15 '17 at 20:14
  • 2
    Have you [done any googling?](http://stackoverflow.com/questions/16500656/which-color-gradient-is-used-to-color-mandelbrot-in-wikipedia) – pingul May 15 '17 at 20:21
  • 1
    The Wikipedia article that you allude to has extensive discussion of coloring algorithms. Why don't your try to implement one of those? – John Coleman May 15 '17 at 20:21
  • 1
    Possible duplicate of [Which color gradient is used to color mandelbrot in wikipedia?](http://stackoverflow.com/questions/16500656/which-color-gradient-is-used-to-color-mandelbrot-in-wikipedia) – John Coleman May 15 '17 at 20:23
  • 1
    Your version is not plain yellow, but plain black. There is nothing you can do about the yellow area (except use black instead, or iterate deeper), but the areas that escape can be coloured by the number of iterations. At a basic level, `R = G = B = iterations % 256`. – Weather Vane May 15 '17 at 20:32
  • 1
    I think my answer to the question [**_Mandelbrot-algorithm - Background color_**](http://stackoverflow.com/questions/16253547/mandelbrot-algorithm-background-color) presents a very general way of doing things that could be adapted to do what you want. – martineau May 15 '17 at 20:37

0 Answers0