montrebase3.py

Created by schraf

Created on November 14, 2021

1.55 KB


from turtle import *
from random import random,randint,choice
from time import sleep

def trait(x, y, a, d):
  penup()
  goto(x, y)
  pendown()
  setheading(a)
  forward(d)

def grille(nb):
  case = min(H,L) // nb
  H_m, L_m = -nb * case / 2, -nb * case /2
  for i in range(1,nb):
    trait(L_m, H_m + case * i, 0, nb * case)
    trait(L_m + case * i, H_m, 90, nb * case)
  return case, H_m, L_m

def cercle(x,y,r,c):
  penup()
  color(c)
  goto(x,y - r)
  setheading(0)
  pendown()
  circle(int(r))

def croix(x,y,r,c):
 for i in [-1,1]:
  penup()
  color(c)
  goto(x - r, y + i * r)
  pendown()
  goto(x + r, y - i * r)

def pion(x,y,r,t1,t2):
  if t1 != t2:
    if t1 == 'o': cercle(x,y,r,"white")
    elif t1 == 'x': croix(x,y,r,"white")
    if t2 == 'o': cercle(x,y,r,"black")
    elif t2 == 'x': croix(x,y,r,"black")

def base3(n):
 chiffres = ''
 while n:
  chiffres = ' ox'[n % 3] + chiffres
  n //= 3
 return ('   '+ chiffres)[-3:]

def aff(nb_preced,nb_suiv,l):
  preced = base3(nb_preced)
  suiv = base3(nb_suiv)
  y = -L_m - case / 2 - case * l
  for c in range(3):
    x = H_m + case / 2 + case * c
    pion(x,y,r,preced[c],suiv[c])

def tictac(h,mn):
  mn += 1
  if mn >= 60:
    mn = 0
    h += 1
    if h > 12: h = 0
  sleep(1)
  return [h, mn]  
  
speed(0)
hideturtle()
L,H = 320, 222
case, H_m, L_m = grille(3)
r = case / 2.3

def go(hm):
  h = hm // 100
  mn = hm % 100
  preced = [0,0,0]
  while True:
    data = [h, mn // 10, mn % 10]
    for l in range(3): aff(preced[l],data[l], l)
    preced = list(data)
    [h, mn] = tictac(h, mn)
    
go(1154)

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>.