# Burning Ship Fractal for CodeSkulptor3 import simplegui # dimensions of screen are in pixels width = 150 height = 110 # scale, pixels per unit on complex plane scale = 40 # offsets # distance of (0, 0) from the top left of the drawing area # in units on complex plane xoff = 2.5 yoff = 2 # Handler to draw on canvas def draw(canvas): lim = 200 # iteration limit # iterate over every pixel for x in range(width): for y in range(height): i = 0 x1 = x / scale - xoff y1 = y / scale - yoff a = 0 b = 0 while (a*a+b*b) < 4 and i < lim: i += 1 c = abs(2 * a * b) a = (a*a-b*b) + x1 try: b = c + y1 except Exception as e: print(repr(e)) i = lim colour = (i >= lim and 'black' or 'hsl(' + str(i*1.5) + ', 100%, 50%)') if not colour == 'black': canvas.draw_point([x, y], colour) print("Finished drawing") def main(): # Create a frame and assign callbacks to event handlers frame = simplegui.create_frame("Burning Ship", width, height) frame.set_draw_handler(draw) # Start the frame animation frame.start() main()