Représentation d’une rosace chaleureuse en Python. Développé par Ilyas R. à l’occasion du DM E22.3 “Des fractales sur NumWorks” édition 2023-2024. #nsi_xyz
from turtle import pos, forward, backward, left, right, pencolor, colormode, speed from kandinsky import * fill_rect(0, 0, 320, 222, (42, 42, 42)) colormode(255) speed(0) def color(x, y): d = (abs(x) ** 2 + abs(y) ** 2) ** 0.5 pencolor(255, round(((d + 20) / 220) * 255), 0) def circle(r): for _ in range(360): color(pos()[0], pos()[1]) move(1, r/60) left(1) def move(t, px): t = backward if not t else forward if t else forward for _ in range(px): color(pos()[0], pos()[1]) t(1) def fractal(n, length): if n == 0: return else: color(pos()[0], pos()[1]) move(1, length/3) circle(length) color(pos()[0], pos()[1]) move(0, length/3*2) move(1, length/3) right(30) fractal(n - 1, length) def run(): for i in range(1, 3): fractal(12, 50*i) run()