cpaslecours.py

Created by maelg0000

Created on April 07, 2026

6.65 KB


from kandinsky import draw_string as ds
from kandinsky import fill_rect as fr
from ion import keydown

W=(255,255,255)
B=(0,0,0)
BL=(0,80,180)
V=(0,120,0)
GR=(80,80,80)
T=(150,0,150)

K_UP=1
K_DOWN=2
K_OK=4
K_BACK=5

# === DICTIONNAIRE DE COMPRESSION ===
# Les mots frequents sont remplaces par §1, §2, etc.
DIC={
    "§E":"equation",
    "§D":"differentielle",
    "§S":"solution",
    "§F":"fonction",
    "§X":"derivable",
    "§R":"reelle",
    "§C":"constante",
    "§P":"propriete",
    "§T":"donc",
    "§V":"variable",
    "§L":"lineaire",
    "§O":"ordre",
    "§H":"homogene",
    "§I":"initiale",
    "§K":"coefficient",
    "§U":"unique",
    "§N":"condition",
    "§M":"forme",
    "§A":"admet",
    "§W":"omega",
    "§Y":"y'",
    "§Z":"y''",
}

def decomp(s):
    for k,v in DIC.items():
        s=s.replace(k,v)
    return s

# === COURS COMPRESSE ===
# Chaque element = 1 ligne
# Prefixes: # = titre, > = important, - = liste, $ = formule, @ = exemple

COURS=[
    "# Equations Differentielles",
    "",
    "#1 INTRODUCTION",
    "",
    "Definition:",
    "Une §E §D est une",
    "relation entre une §V §R x,",
    "une §F f et ses derivees",
    "f', f'', f'''...",
    "",
    "Resoudre = trouver toutes",
    "les §Fs qui satisfont",
    "cette relation.",
    "",
    "@ Exemple: §Y(x) = 3x^2",
    "  §S: y(x) = x^3 + c",
    "  (c = §C §R)",
    "",
    "> Avec §N §I y(0)=1:",
    "> §S §U: y(x) = x^3 + 1",
    "",
    "#2 TYPE §Y + a*y = 0",
    "",
    "§P:",
    "Les §Ss de §Y + a*y = 0",
    "sont de la §M:",
    "",
    "$ f(x) = k*exp(-a*x)",
    "$ ou k est une §C §R",
    "",
    "@ Ex1: §Y - 3y = 0",
    "  §S: f(x) = k*exp(3x)",
    "",
    "@ Ex2: 2*§Y = -5y",
    "  => §Y + 2.5*y = 0",
    "  §S: f(x) = k*exp(-2.5x)",
    "",
    "#3 TYPE §Y + a*y = b",
    "",
    "§P:",
    "Les §Ss de §Y + a*y = b",
    "(avec a different de 0)",
    "sont de la §M:",
    "",
    "$ f(x) = k*exp(-ax) + b/a",
    "",
    "@ Ex: §Y + 2y = 4",
    "  a=2, b=4, b/a=2",
    "  §S: f(x) = k*exp(-2x) + 2",
    "",
    "#4 CAUCHY-LIPSCHITZ",
    "",
    "§P (Unicite):",
    "L'§E §D §Y + a*y = b",
    "§A une §U §S f §X sur R",
    "verifiant f(x0) = y0.",
    "",
    "@ Ex: §Y - 0.5*y = 2",
    "  avec f(0) = 1",
    "",
    "  1) §S generale:",
    "     f(x) = k*exp(0.5x) - 4",
    "",
    "  2) §N f(0) = 1:",
    "     k*exp(0) - 4 = 1",
    "     k - 4 = 1",
    "     k = 5",
    "",
    "  3) §S:",
    "     f(x) = 5*exp(0.5x) - 4",
    "",
    "#5 TYPE §Z + w^2*y = 0",
    "",
    "§P:",
    "Les §Ss de §Z + w^2*y = 0",
    "(w different de 0)",
    "sont de la §M:",
    "",
    "$ f(x) = L*cos(wx) + M*sin(wx)",
    "$ ou L,M sont des §Cs §Rs",
    "",
    "@ Ex1: §Z + 4y = 0",
    "  w^2=4 §T w=2",
    "  §S: f(x) = L*cos(2x)",
    "           + M*sin(2x)",
    "",
    "@ Ex2: 27*§Z + 3y = 0",
    "  §Z + (1/9)y = 0",
    "  w = 1/3",
    "  §S: f(x) = L*cos(x/3)",
    "           + M*sin(x/3)",
    "",
    "#6 FORMULES TRIGO",
    "",
    "Utiles pour transformer:",
    "L*cos(wx)+M*sin(wx)",
    "en A*cos(wx+phi)",
    "ou A*sin(wx+phi)",
    "",
    "$ cos(a+b) = cos(a)cos(b)",
    "$          - sin(a)sin(b)",
    "",
    "$ sin(a+b) = cos(a)sin(b)",
    "$          + sin(a)cos(b)",
    "",
    "#7 UNICITE ORDRE 2",
    "",
    "§P (Cauchy-Lipschitz):",
    "L'§E §Z + w^2*y = 0",
    "§A une §U §S f sur R",
    "avec DEUX §Ns §Is.",
    "",
    "> §Ns possibles:",
    "> { f(x0) = y0",
    "> { f'(x0) = y1",
    "",
    "ou",
    "",
    "> { f(x0) = y0",
    "> { f(x1) = y1",
    "",
    "@ Ex: 4§Z + pi^2*y = 0",
    "  avec f(0.5) = sqrt(2)/2",
    "  et f'(0.5) = 0",
    "",
    "  1) w = pi/2",
    "  f(x) = L*cos(pi*x/2)",
    "       + M*sin(pi*x/2)",
    "",
    "  2) f(0.5) = sqrt(2)/2",
    "  L*cos(pi/4)+M*sin(pi/4)",
    "  = sqrt(2)/2*(L+M)",
    "  §T L+M = 1",
    "",
    "  3) f'(0.5) = 0",
    "  f'(x) = -L*pi/2*sin(..)",
    "        + M*pi/2*cos(..)",
    "  §T -L+M = 0",
    "",
    "  4) Systeme:",
    "  { L+M = 1",
    "  { -L+M = 0",
    "  => L = M = 0.5",
    "",
    "  5) §S:",
    "  f(x) = 0.5*cos(pi*x/2)",
    "       + 0.5*sin(pi*x/2)",
    "",
    "=== FIN DU COURS ===",
]

def get_color(line):
    if line.startswith("#"):
        return T
    if line.startswith(">"):
        return BL
    if line.startswith("$"):
        return V
    if line.startswith("@"):
        return (200,100,0)
    return B

def clean(line):
    if len(line)>0 and line[0] in "#>$@":
        return line[1:].strip()
    return line

def show_cours():
    lines=[]
    for l in COURS:
        txt=decomp(l)
        # Couper les lignes trop longues
        while len(txt)>31:
            lines.append((txt[:31],get_color(l)))
            txt=" "+txt[31:]
        lines.append((clean(txt),get_color(l)))
    
    total=len(lines)
    scroll=0
    maxl=11
    
    while True:
        fr(0,0,320,222,W)
        
        # Header
        fr(0,0,320,20,(50,50,150))
        ds("COURS: Eq. Diff.",80,2,W,(50,50,150))
        
        # Lignes
        y=24
        for i in range(scroll,min(scroll+maxl,total)):
            txt,col=lines[i]
            ds(txt,5,y,col,W)
            y+=18
        
        # Scrollbar visuelle
        if total>maxl:
            sbh=180*maxl//total
            sby=22+180*scroll//total
            fr(315,22,4,180,(220,220,220),W)
            fr(315,sby,4,sbh,(100,100,200),W)
        
        # Footer
        fr(0,205,320,17,(240,240,240))
        pg=str(scroll//maxl+1)+"/"+str((total-1)//maxl+1)
        ds("[^v]scroll [<]quit "+pg,5,207,GR,(240,240,240))
        
        # Input
        while True:
            if keydown(K_UP):
                if scroll>0:
                    scroll-=1
                while keydown(K_UP):pass
                break
            if keydown(K_DOWN):
                if scroll+maxl<total:
                    scroll+=1
                while keydown(K_DOWN):pass
                break
            if keydown(K_BACK):
                return
            if keydown(K_OK):
                # Page down rapide
                scroll=min(scroll+maxl,total-maxl)
                if scroll<0:scroll=0
                while keydown(K_OK):pass
                break

def menu():
    while True:
        fr(0,0,320,222,W)
        ds("COURS MATHS",100,20,(50,50,150),W)
        ds("Terminale STI2D",90,45,GR,W)
        
        ds("1. Eq. Differentielles",30,90,B,W)
        ds("   [OK] pour ouvrir",30,110,BL,W)
        
        ds("Taille: "+str(len(COURS))+" lignes",30,150,GR,W)
        
        ds("[BACK] quitter",30,190,GR,W)
        
        while True:
            if keydown(K_OK):
                while keydown(K_OK):pass
                show_cours()
                break
            if keydown(K_BACK):
                return

menu()

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.