calpylite.py

Created by maelg0000

Created on February 08, 2026

1.78 KB


from kandinsky import draw_string, fill_rect
from ion import keydown, KEY_OK

def pi_ultra_light():
    # Setup ecran initial
    BG = (255, 255, 255)
    fill_rect(0, 0, 320, 222, BG)
    draw_string("PI EN DIRECT", 100, 5, (0, 0, 255))
    
    # Parametres : 500 decimales pour ne pas saturer la RAM
    n = 500
    len_a = int(10 * n / 3) + 1
    
    try:
        a = [2] * len_a
    except MemoryError:
        draw_string("Erreur RAM", 10, 50, (255, 0, 0))
        return

    x, y = 10, 50
    cnt = 0

    for j in range(n):
        q = 0
        for i in range(len_a - 1, -1, -1):
            x_val = 10 * a[i] + q * (i + 1)
            a[i] = x_val % (2 * i + 1)
            q = x_val // (2 * i + 1)
        
        a[0] = q % 10
        digit = q // 10
        
        # Formatage du texte
        char = str(digit)
        if cnt == 0:
            char += "." # Affiche "3." au tout debut
        
        # Affichage du compteur (on efface juste le chiffre precedent)
        fill_rect(110, 25, 100, 18, BG)
        draw_string("Decimales: " + str(cnt), 10, 25, (255, 0, 0))
        
        # Affichage de la decimale
        draw_string(char, x, y, (0, 0, 0))
        
        # Calcul de la position suivante
        # Si c'est "3.", on decale un peu plus
        x += 20 if cnt == 0 else 10
        
        if x > 300:
            x = 10
            y += 18
            
        # Si on arrive en bas de l'ecran
        if y > 200:
            # On efface la zone de texte mais on garde le titre
            fill_rect(0, 50, 320, 172, BG)
            x, y = 10, 50
            
        cnt += 1
        
        # Touche OK pour stopper manuellement
        if keydown(KEY_OK):
            break

    draw_string("TERMINE", 120, 205, (0, 150, 0))

# Lancement direct
pi_ultra_light()

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.