def line(x, y, xx, yy): # (x,y) to (xx,yy) if x > xx: t = x # Swap co-ordinates if necessary x = xx xx = t t = y y = yy yy = t if xx - x == 0: # Avoid div by zero if vertical vert(x, min(y, yy), max(y, yy)) else: # Draw line one dot at a time L to R n = xx - x + 1 grad = float((yy - y) / (xx - x)) # Calculate gradient for i in range(n): y3 = y + int(grad * i) display.pixel(x + i, y3) # One dot at a time
RealStart = -2 * zoom RealEnd= 1 * zoom ImaginaryStart = -1 * zoom ImaginaryEnd = 1 * zoom display.clear() #One of the issues on the video was it was displaying the old images whilst generating the new one #So added the update below to send a clear screen to the display display.update() go = True while go: for x in range(0, width): for y in range(0, height): c = complex(RealStart + (x / width) * (RealEnd - RealStart),ImaginaryStart + (y / height) * (ImaginaryEnd - ImaginaryStart)) m = mandelbrot(c) colour = 255 - int(m * 255 / iterations) display.set_pen(colour,0,155) display.pixel(x, y) #uncomment this line if you want to see the progress the plot has made if you are not updating the screen every x #print(x) #if you put the display update here it will update every x line display.update() #if you put the display update here it will update at the end of processing (maybe 2 to 3 minutes in) #display.update() go = False
def horiz(l, t, r): # left, top, right n = r - l + 1 # Horizontal line for i in range(n): display.pixel(l + i, t)
def vert(l, t, b): # left, top, bottom n = b - t + 1 # Vertical line for i in range(n): display.pixel(l, t + i)
def display_pixel(self, x, y): display.pixel(x, y)