nsi_e22.py

Created by ilyas-r

Created on October 05, 2023

938 Bytes

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()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.