nsi_e22.py

Created by granier-kloon

Created on October 14, 2025

1.77 KB

ouidakor


from kandinsky import *
from math import cos, sin, pi
def ligne(x1, y1, x2, y2, ep, c):
    dx, dy = x2 - x1, y2 - y1; steps = int(max(abs(dx), abs(dy)))
    if steps > 0:
        for s in range(steps):
            for i in range(ep):
                for j in range(ep):
                    px = int(x1 + dx * s / steps + i - ep//2); py = int(y1 + dy * s / steps + j - ep//2)
                    if 0 <= px < 320 and 0 <= py < 222: set_pixel(px, py, c)
def fractale_lotus(x, y, r, a, p, c):
    if p == 0 or r < 3: return
    nb_petales = 8
    for i in range(nb_petales):
        ang = a + i * 2*pi/nb_petales
        for j in range(3):
            r1 = r * (0.3 + j * 0.35); r2 = r * (0.3 + (j+1) * 0.35); ang_offset = (j - 1) * 0.15
            x1 = int(x + r1 * cos(ang + ang_offset)); y1 = int(y + r1 * sin(ang + ang_offset))
            x2 = int(x + r2 * cos(ang + ang_offset)); y2 = int(y + r2 * sin(ang + ang_offset))
            ligne(x1, y1, x2, y2, max(1, 3-p), c)
    if p > 1:
        for i in range(nb_petales):
            ang = a + i * 2*pi/nb_petales; x2 = int(x + r * cos(ang)); y2 = int(y + r * sin(ang))
            fractale_lotus(x2, y2, r*0.35, ang, p-1, c)
def fractale_reseau(x, y, l, a, p, c):
    if p == 0 or l < 4: return
    for i in range(6):
        ang = a + i * pi/3; x2 = int(x + l * cos(ang)); y2 = int(y + l * sin(ang)); ligne(x, y, x2, y2, 1, c); fractale_reseau(x2, y2, l*0.5, a, p-1, c)
for y in range(222): r = int(30 + y/222 * 25); g = int(25 + y/222 * 30); b = int(65 + y/222 * 35); fill_rect(0, y, 320, 1, (r, g, b))
positions_reseau = [(60, 50), (160, 50), (260, 50), (60, 111), (260, 111), (60, 172), (160, 172), (260, 172)]
for px, py in positions_reseau: fractale_reseau(px, py, 25, 0, 4, (60, 90, 110))
fractale_lotus(160, 111, 75, 0, 3, (120, 240, 255))

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.