psm_bulles.py

Created by cent20

Created on June 16, 2024

1 KB

Ce script génère des bulles de savon colorées


from kandinsky import *
import math
import random

def soap_bubbles():
    def draw_circle(cx, cy, radius, color):
        for x in range(cx - radius, cx + radius):
            for y in range(cy - radius, cy + radius):
                if 0 <= x < 320 and 0 <= y < 222:
                    dx, dy = x - cx, y - cy
                    if dx * dx + dy * dy <= radius * radius:
                        r = color[0] - int(255 * (dx * dx + dy * dy) / (radius * radius))
                        g = color[1] - int(255 * (dx * dx + dy * dy) / (radius * radius))
                        b = color[2] - int(255 * (dx * dx + dy * dy) / (radius * radius))
                        set_pixel(x, y, (r, g, b))

    for _ in range(20):  # Draw 20 bubbles
        cx = random.randint(50, 270)
        cy = random.randint(50, 172)
        radius = random.randint(10, 40)
        color = (random.randint(100, 255), random.randint(100, 255), random.randint(100, 255))
        draw_circle(cx, cy, radius, color)

soap_bubbles()