cats.py

Created by schraf

Created on May 16, 2024

947 Bytes


import turtle
import math

t = turtle
t.speed(0)
t.pensize(1)

r2  = math.sqrt(2)
instructions = [
      -45, 2 * r2, 45, 3, 90, 1, 90, 2,
      -90, 1, -90, 3, -45, 3 * r2, -90, r2,
      45, 5, -45, r2, -90, r2, -90, r2,
      45, 3, 135, r2, -45, 2, -45, r2, 135, 3,
      -135, r2, 45, 2, 45, r2, -135, 3, -45, r2,
      90, 2 * r2, -90, 2 * r2, 90, r2
]

def tracer_chat(taille):
  for angle, coeff in zip(instructions[::2], instructions[1::2]):
    t.right(angle) 
    t.forward(coeff * taille)

taille = 4
nombre_lignes = 6
nombre_chats_par_ligne = 10
espacement_x = 10 * taille
espacement_y = 11 * taille

for ligne in range(nombre_lignes):
  for chat in range(nombre_chats_par_ligne):
    position_x = -160 + chat * espacement_x - 2 * taille * (ligne % 5)
    position_y = -110 + ligne * espacement_y
    t.penup()
    t.goto(position_x, position_y)
    t.setheading(0)
    t.pendown()
    tracer_chat(taille)

t.hideturtle()