fromkandinskyimportdraw_string,fill_rectfromionimportkeydown,KEY_OK,KEY_UP,KEY_DOWNdefdisplay_zone(digits,scroll_y):# On garde les 2 premieres lignes intactes (Titre + Compteur)
fill_rect(0,50,320,172,(255,255,255))curr_x,curr_y=10,50-scroll_yfordindigits:ifcurr_y>=50andcurr_y<=200:draw_string(d,curr_x,curr_y,(0,0,0))curr_x+=10ifcurr_x>300:curr_x=10curr_y+=18defpi_calc():# Setup
fill_rect(0,0,320,222,(255,255,255))draw_string("PI CALCULATOR",100,5,(0,0,255))digits=[]# Parametres Spigot pour un bloc
n=1000# On calcule par blocs de 1000 pour la stabilite
len_a=int(10*n/3)+1a=[2]*len_ax,y=10,50scroll_offset=0forjinrange(n):q=0foriinrange(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%10val=q//10# Formatage du chiffre
char=str(val)iflen(digits)==1:digits[0]=digits[0]+"."digits.append(char)# Affichage direct
draw_string("Decimales: "+str(len(digits)-1),10,25,(255,0,0))# On affiche le "3." correctement au debut
to_print=chariflen(digits)==1:to_print=char+"."draw_string(to_print,x,y-scroll_offset,(0,0,0))# Avancement curseur
x+=10ifx>300:x=10y+=18ify-scroll_offset>200:scroll_offset+=18display_zone(digits,scroll_offset)# Pause / Navigation
ifkeydown(KEY_OK):draw_string("PAUSE",135,205,(255,0,0))whilekeydown(KEY_OK):passpaused=Truewhilepaused:ifkeydown(KEY_UP)andscroll_offset>=18:scroll_offset-=18display_zone(digits,scroll_offset)whilekeydown(KEY_UP):passifkeydown(KEY_DOWN):scroll_offset+=18display_zone(digits,scroll_offset)whilekeydown(KEY_DOWN):passifkeydown(KEY_OK):paused=Falsefill_rect(0,205,320,18,(255,255,255))display_zone(digits,scroll_offset)whilekeydown(KEY_OK):passdraw_string("FIN DU BLOC",110,205,(0,150,0))# Lancement
pi_calc()
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
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.