test.py

Created by leno-m

Created on April 14, 2025

1.33 KB


from kandinsky import *

def adjust_color(color, dr, dg, db):
    r = min(max(color[0] + dr, 0), 255)
    g = min(max(color[1] + dg, 0), 255)
    b = min(max(color[2] + db, 0), 255)
    return (r, g, b)

def draw_tetris_block(x, y, size, base_color, mode="out"):
    border = max(2, size // 8)

    # Déduction automatique
    light = adjust_color(base_color, +40, +40, +40)
    dark  = adjust_color(base_color, -50, -50, -50)
    inner = adjust_color(base_color, -20, -10, -30)

    # Mode 3D extérieur ("out") ou intérieur ("in")
    if mode == "out":
        top_left = light
        bottom_right = dark
    else:  # "in"
        top_left = dark
        bottom_right = light

    # Bloc principal
    fill_rect(x, y, size, size, base_color)

    # Bord haut-gauche
    for i in range(border):
        fill_rect(x + i, y, size - 2*i, 1, top_left)
        fill_rect(x, y + i, 1, size - 2*i, top_left)

    # Bord bas-droit
    for i in range(border):
        fill_rect(x + i, y + size - 1 - i, size - 2*i, 1, bottom_right)
        fill_rect(x + size - 1 - i, y + i, 1, size - 2*i, bottom_right)

    # Centre
    inset = border + 1
    fill_rect(x + inset, y + inset, size - 2*inset, size - 2*inset, inner)

draw_tetris_block(10, 10, 50, (255, 0, 100), mode="out")  # 3D positif
draw_tetris_block(70, 10, 50, (255, 0, 100), mode="in")   # 3D négatif

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.