frommathimport*fromkandinskyimport*fromrandomimport*fromtimeimport*# couleurs et dessin du coeur
BLA=(255,255,255)ROS=(210,130,180)ROU=(210,30,60)NOI=(0,0,0)coul=[BLA,ROS,ROU,NOI]cases=[[0,0,1,1,1,1,0,0,0,1,1,1,1,0,0],[0,1,1,1,1,1,1,0,1,1,1,1,1,1,0],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,3,3,1,3,3,1,1,1,1,1],[1,1,1,1,3,2,2,3,2,0,3,1,1,1,1],[0,1,1,1,3,2,2,2,2,2,3,1,1,1,0],[0,1,1,1,1,3,2,2,2,3,1,1,1,1,0],[0,0,1,1,1,1,3,2,3,1,1,1,1,0,0],[0,0,0,1,1,1,1,3,1,1,1,1,0,0,0],[0,0,0,0,1,1,1,1,1,1,1,0,0,0,0],[0,0,0,0,0,1,1,1,1,1,0,0,0,0,0],[0,0,0,0,0,0,1,1,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,1,0,0,0,0,0,0,0]]# dimensions et position du coeur
largeur,hauteur=len(cases[0]),len(cases)gauche,haut=8,4classballe():def__init__(self):self.x=randint(1,20)self.y=randint(15,20)# direction deplacement
self.vx=1ifrandom()<0.5else-1self.vy=1defaff(self,x1,y1,x2,y2):# si deplacement, on efface case precedente et affiche suivante
fill_rect(10*x1,10*y1,10,10,BLA)fill_rect(10*x2,10*y2,10,10,NOI)self.x=x2self.y=y2defbouge(self):# position suivante avec effet aleatoire
xx=max(0,min(31,self.x+self.vx+randint(-1,1)))yy=max(0,min(21,self.y+self.vy))# bords ? Si oui rebond
ifxx==0orxx==31:self.vx*=-1ifyy==0oryy==21:self.vy*=-1# On est dans le cadre du dessin ?
try:# La case n'est pas vide ?
ifcases[yy-haut][xx-gauche]>0:# rebond
self.vx*=-1self.vy*=-1# si c'est du rose, on efface
ifcases[yy-haut][xx-gauche]==1:cases[yy-haut][xx-gauche]=0else:# la case est vide, on deplace la balle
self.aff(self.x,self.y,xx,yy)# on est a l'exterieur du cadre donc deplacement
except:self.aff(self.x,self.y,xx,yy)defplateau(cases):forl,tinenumerate(cases):forc,vinenumerate(t):# la couleur depend de la valeur de la case 0 = BLA, 1 = ROS...
fill_rect(10*gauche+10*c,10*haut+10*l,10,10,coul[v])plateau(cases)# creation de 5 balles
balles=[]forkinrange(12):balles.append(balle())depart=monotonic()whileTrue:forbinballes:b.bouge()sleep(0.03)s=sum([r.count(0)forrincases])ifs==169:fill_rect(0,0,320,222,BLA)plateau(cases)break#calcul du nb de jours et affichage
jours=int((monotonic()-depart)/3)draw_string(str(jours)+" jours",120,180,ROS)
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.