nageurs_simul_de.py

Created by schraf

Created on July 20, 2023

997 Bytes

Faites vos jeux et devinez qui finira premier de cette course de natation !
Vous pouvez vous servir de ce programme pour déterminer dans quel ordre des personnes devront participer à une activité.

Explications en vidéo

Si vous voulez mettre le rang du joueur à droite plutôt que l’ordre d’arrivée, il suffit de remplacer la ligne :
draw_string(str(i+1),300,19+35*rg)
par celle-ci :
draw_string(str(rg+1),300,19+35*i)


from kandinsky import *
from random import *

p0=[0,0,0,6152,9236,17378,1004,1020,1004,17378,9236,6152,0,0,0,0]
p1=[8192,4096,2048,1024,1052,994,1005,1020,1005,994,1052,1024,2048,4096,8192,0]
p2=[0,2,16388,8200,6160,2016,1004,1020,1004,2016,6160,8200,16388,2,0,0]
p3=[0,0,384,96,24,1016,65531,1023,65531,1016,24,96,384,0,0,0]

nager=[p0,p1,p2,p3]
bleu=(0,0,255)
jaune=(255,255,0)
blanc=(255,255,255)


def dessin(x,y,pos):
  for c in range(16):
    for l in range(16):
      set_pixel(x+c,y+l, blanc if pos[l]>>c & 1 else bleu)

def go():
  pos=[300]*6
  rg=0
  fill_rect(0,0,320,222,bleu)
  for i in range(6):
    draw_string(str(i+1),0,19+35*i)
    for j in range(320):
      set_pixel(j,10+35*i,jaune if j%4!=0 else bleu)  

  while max(pos)>10:
    i=randint(0,5)
    if random()<.005 and pos[i]>10:
      dessin(pos[i],20+35*i,nager[pos[i]%4])
      pos[i]-=1
      if pos[i]==10:
        draw_string(str(i+1),300,19+35*rg)
        rg+=1
        
def swim(): go()

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 <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.