# montretictac.py

Created by schraf

Created on November 16, 2021

1.51 KB

```from turtle import *
from time import sleep

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

def grille(c,l):
H_m, L_m = -l * case / 2, -c * case /2
for i in range(1,max(c,l)):
if i < l: trait(L_m, H_m + case * i, 0, 3 * case)
if i < c: trait(L_m + case * i, H_m, 90, 5 * case)
return H_m + c * case / 2, -L_m + case / 2

def cercle(x,y,r,c):
penup()
color(c)
goto(x,y - r)
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 = ''
for _ in range(3):
chiffres = ' ox'[n % 3] + chiffres
n //= 3
return chiffres

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

def tictac(h,m,s):
s = (s + 1) % 60
if s == 0:
m = (m + 1) % 60
if m == 0: (h + 1) % 12
sleep(1)
return [h, m,s]

speed(0)
hideturtle()
case = 44
H_m, L_m = grille(3,5)
r = case / 2.3

def go(hh,mn = 0,ss = 0):
preced = [0,0,0,0,0]
while True:
data = [hh, mn // 10, mn % 10, ss // 10, ss % 10]
aff(preced,data)
preced = list(data)
[hh, mn, ss] = tictac(hh, mn, ss)

go(11,44,36)```