Exemple #1
0
 def line(x1, y1, x2, y2):
     b = BasicShapes
     if x1 > x2:
         b.line(x2, y2, x1, y1)
         return b.line
     try:
         slope = (y2 - y1) / (x2 - x1)
     except ZeroDivisionError as e:
         for y in range(min(y1, y2), max(y1, y2)):
             k.set_pixel(x1, y, Options.stroke())
         return b.line
     for x in range(abs(x1 - x2)):
         k.set_pixel(x1 + x, y1 + round(slope * x), Options.stroke())
     return b.line
Exemple #2
0
def mandelbrot(N_iteration):
    for x in range(320):
        for y in range(222):
            # Compute the mandelbrot sequence for the point c = (c_r, c_i) with start value z = (z_r, z_i)
            z = complex(0, 0)
            # Rescale to fit the drawing screen 320x222
            c = complex(3.5 * x / 319 - 2.5, -2.5 * y / 221 + 1.25)
            i = 0
            while (i < N_iteration) and abs(z) < 2:
                i = i + 1
                z = z * z + c


# Choose the color of the dot from the Mandelbrot sequence
            rgb = int(255 * i / N_iteration)
            col = kandinsky.color(int(rgb), int(rgb * 0.75), int(rgb * 0.25))
            # Draw a pixel colored in 'col' at position (x,y)
            kandinsky.set_pixel(x, y, col)
Exemple #3
0
    def line(x1, y1, x2, y2):
        x_length = abs(x1 - x2)
        y_length = abs(y1 - y2)

        if x1 > x2:
            return BasicShapes.line(x2, y2, x1, y1)

        try:
            slope = (y2 - y1) / (x2 - x1)
        except ZeroDivisionError as e:
            # Can't calculate slope due to 0 division (vertical lines)
            x = x1
            for y in range(min(y1, y2), max(y1, y2)):
                ky.set_pixel(x, y, Options.stroke())
            return

        for x in range(x_length):
            y = round(slope * x)
            ky.set_pixel(x1 + x, y1 + y, Options.stroke())
Exemple #4
0
 def point(x, y):
     ky.set_pixel(x, y, Options.stroke())
     return BasicShapes