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()

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