biorythme.py

Created by schraf

Created on May 29, 2025

2.65 KB


from kandinsky import *
from ion import keydown
from time import sleep
from math import sin, pi

CYCLES = [(23, 'PHY', 'red'),(28, 'EMO', 'blue'),(33, 'INT', 'green')]
JSEM = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
COUL = (255, 0, 0), (0, 0, 255), (0, 180, 0)
MOIS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

def utile(dd, mm, yy):
    tempo = list(MOIS)
    days = (yy - 1901) * 365
    ly1, ly2 = divmod(yy - 1901, 4)
    days += ly1
    if ly2 == 3: tempo[2] = 29
    days += sum(tempo[:mm])
    days += dd
    wkdays = (days % 7) + 1
    return days, wkdays

def avance(dd, mm, yy):
    tempo = list(MOIS)
    if yy % 4 == 0: tempo[2] = 29
    dd += 1
    if dd > tempo[mm]:
     mm += 1
     dd = 1
     if mm > 12:
        mm = 1
        yy += 1
    return (dd, mm, yy)

def recule(dd, mm, yy):
    tempo = list(MOIS)
    if yy % 4 == 0: tempo[2] = 29
    dd -= 1
    if dd == 0:
     mm -= 1
     if mm == 0:
        mm = 12
        yy -= 1
     dd = tempo[mm]   
    return (dd, mm, yy)    

def tracer_biorythmes(ddays):
    largeur = 320
    hauteur = 222
    jours = 33
    pixels_par_jour = largeur // jours
    y_centre = hauteur // 2
    amplitude = hauteur // 3

    fill_rect(0, 0, 320, 222, (255, 255, 255))
    for i in range(11):
        fill_rect(15, int(y_centre + amplitude - amplitude / 5 * i), 295, 1, (240,) * 3)
    fill_rect(0, y_centre, largeur, 1, (200,) * 3)

    for i in range(3):
        duree = CYCLES[i][0]
        j_courant = ddays % duree
        for x in range(largeur):
            j = x / pixels_par_jour
            if j <= duree:
                angle = 2 * pi * (ddays + j) / duree
                y = int(y_centre - amplitude * sin(angle))
                tt = 8 if j == duree else 1
                fill_rect(9 + x - tt // 2, y - tt // 2, tt, tt, COUL[i])
        draw_string(CYCLES[i][1], 15 + 50 * i, 12, CYCLES[i][2])

def draw_date(dd, mm, yy):
    _, wk = utile(dd, mm, yy)
    draw_string("{} {}/{}/{}".format(JSEM[wk - 1], dd, mm, yy), 15, 200, (0, 0, 0))

def draw_jours(ddays):
    draw_string("{} days".format(ddays), 195, 200, (0, 0, 0))

def wait_key():
    while True:
        if keydown(0): return "LEFT"
        if keydown(3): return "RIGHT"
        sleep(0.02)

dd1, mm1, yy1 = map(int,input("BIRTH dd/mm/yyyy : ").split('/'))
dd2, mm2, yy2 = map(int,input(" DATE dd/mm/yyyy : ").split('/'))
d1, _ = utile(dd1, mm1, yy1)

while True:
    d2, _ = utile(dd2, mm2, yy2)
    ddays = d2 - d1
    tracer_biorythmes(ddays)
    draw_date(dd2, mm2, yy2)
    draw_jours(ddays)
    k = wait_key()
    sleep(.1)
    if k == "RIGHT": dd2, mm2, yy2 = avance(dd2, mm2, yy2)
    elif k == "LEFT": dd2, mm2, yy2 = recule(dd2, mm2, yy2)

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.