zwemmers.py

Created by numworks-nl

Created on July 29, 2021

2.88 KB


from kandinsky import *
from random import *

black = color(0,0,0)
white = color(255,255,255)


p1=[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0],[0,0,1,0,1,0,0,0,0,0,1,0,0,1,0,0],[0,1,0,0,0,1,1,1,1,1,0,0,0,0,1,0],[0,0,1,1,0,1,1,1,1,1,0,0,0,0,0,0],[0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0],[0,0,1,1,0,1,1,1,1,1,0,0,0,0,0,0],[0,1,0,0,0,1,1,1,1,1,0,0,0,0,1,0],[0,0,1,0,1,0,0,0,0,0,1,0,0,1,0,0],[0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]
p2=[[0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0],[0,0,1,1,1,0,0,0,0,0,1,0,0,0,0,0],[0,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0],[1,0,1,1,0,1,1,1,1,1,0,0,0,0,0,0],[0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0],[1,0,1,1,0,1,1,1,1,1,0,0,0,0,0,0],[0,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0],[0,0,1,1,1,0,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,0,0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0,0,1,1,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]
nage=[p1,p2,p3,p4]

def draw_swimmer(x,y,pos):
   for i in range (16):
     for j in range (16):
       set_pixel (x+i,y+j,black if pos[j][i]==1 else white)

def draw_pool():
  for i in range (6):
      draw_string(str(i+1),0,19+35*i)
      for n in range (320):
        set_pixel(n,10+35*i,black)

def swim():
  draw_pool()
  pos=[300,300,300,300,300,300]
  rang=0
  for j in range (6):
    draw_swimmer(300,20+35*j,p1)
  while max(pos)>10:
    i=randint(0,5)
    if pos[i]>10:
      draw_swimmer(pos[i]-1,20+35*i,nage[pos[i]%4])
      pos[i]=pos[i]-1
      if pos[i]==10:
        rang=rang+1
        draw_string(str(rang),300,19+35*i)

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.