mx04.py

Created by ilyas-r

Created on November 01, 2023

1.16 KB

“Golden disc” en Python. Développé par Ilyas R. à l’occasion du DM MX4 “Les mathématiques sont belles : cercles” édition 2023-2024. #nsi_xyz


from kandinsky import *

colors = [(250, 214, 67), (244, 206, 58), (237, 197, 49), (219, 180, 44), (201, 162, 39), (164, 126, 27), (146, 108, 21), (118, 82, 14)]
colors_r = list(reversed(colors))

def cercle(x, y, r, e, c):
    for i in range(r+1):
        for j in range(r+1):
            hypotenuse_theoretical = (r//2)**2
            hypotenuse_calculated = round(i**2+j**2)
            if abs(hypotenuse_theoretical - hypotenuse_calculated) <= e*(r//2):
                    set_pixel(x+j, y+i, c)
                    set_pixel(x-j, y-i, c)
                    set_pixel(x+j, y-i, c)
                    set_pixel(x-j, y+i, c)


def ligne(x, y, radius, direction, offset, c):
    x_offset = 0 if direction not in (0, 3) else (offset if direction == 3 else -offset)
    y_offset = 0 if direction not in (1, 2) else (offset if direction == 2 else -offset)
    for i in range(len(c)):
        cercle(x+x_offset*i, y+y_offset*i, radius, radius//2, c[i])


fill_rect(0, 0, 320, 222, (234, 218, 162))
ligne(180, 50, 50, 3, 11, colors)
ligne(180, 121, 50, 3, 11, colors_r)
ligne(111, 50, 48, 2, 11, colors_r)
ligne(63, 110, 20, 2, 5, colors)
ligne(200, 186, 40, 0, 9, colors)