psm_fractales.py

Created by cent20

Created on June 16, 2024

933 Bytes

Ce script génère des galaxies spiralées avec des étoiles colorées.


from kandinsky import *
import random
import math

def fractal_plants():
    def draw_branch(x, y, angle, length, depth):
        if depth == 0 or length < 1:
            return
        x_end = x + int(math.cos(angle) * length)
        y_end = y + int(math.sin(angle) * length)
        if 0 <= x_end < 320 and 0 <= y_end < 222:
            color = (0, random.randint(100, 255), 0)
            set_pixel(x_end, y_end, color)
            draw_branch(x_end, y_end, angle + random.uniform(0.1, 0.5), length * 0.75, depth - 1)
            draw_branch(x_end, y_end, angle - random.uniform(0.1, 0.5), length * 0.75, depth - 1)
    
    for _ in range(10):  # Draw 10 plants
        x = random.randint(100, 220)
        y = random.randint(150, 200)
        angle = -math.pi / 2
        length = random.randint(30, 50)
        depth = random.randint(3, 6)
        draw_branch(x, y, angle, length, depth)

fractal_plants()

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.