bateau_anime.py

Created by laurent-cortot

Created on February 03, 2020

1.39 KB

Bateau navigant sur l’eau


from kandinsky import *
import time

# Configuration espace NumWorks
xMax = 320
yMax = 220

# Trace un carré par case ; 1 => noir
def traceGrille(grille, tCase, x, y):
  # boucle sur chaque ligne
  for iL in range(len(grille)):
    # boucle sur chaque ligne
    for iC in range(len(grille[iL])):
      if grille[iL][iC] == 1:
        couleurC = color(0,0,0)
      else:
        couleurC = color(255,255,255)
      fill_rect(x+tCase*iC,y+tCase*iL, \
                tCase,tCase,couleurC)

# Retourne une liste de liste vide
# de carrés de c = tCase
def grilleVide(tCase):
  LL = []
  # boucle sur chaque ligne
  for iL in range(yMax//tCase):
    # boucle sur chaque colonne via range
    LL.append([0 for iC in range(xMax//tCase)])
  return LL

# Défini le motif sous forme de
# liste de liste
def motifBateau():
  L01 = [0,0,0,0,1,0,0,0,0,0]
  L02 = [0,0,0,0,1,1,0,0,0,0]
  L03 = [0,0,0,0,1,1,1,0,0,0]
  L04 = [0,0,0,0,1,1,1,1,0,0]
  L05 = [0,0,0,0,1,0,0,0,0,0]
  L06 = [0,0,0,0,1,0,0,0,0,0]
  L07 = [0,0,0,0,1,0,0,0,0,0]
  L08 = [1,1,1,1,1,1,1,1,1,1]
  L09 = [0,1,1,1,1,1,1,1,1,0]
  L10 = [0,0,1,1,1,1,1,1,0,0]
  return [L01,L02,L03,L04,L05,L06,L07,L08,L09,L10]



""" Programme principal """
tailleCase = 10
y = 50
for x in range(xMax):
  # efface trace précédente
  gVide = grilleVide(tailleCase)
  traceGrille(gVide, tailleCase,0,0)
  traceGrille(motifBateau(), tailleCase,x,y)
  time.sleep(0.001)

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.