Skip to content

Instantly share code, notes, and snippets.

@stephengruppetta
Created December 18, 2023 11:15
Show Gist options
  • Save stephengruppetta/4bd2fbc99778511834314ba964241389 to your computer and use it in GitHub Desktop.
Save stephengruppetta/4bd2fbc99778511834314ba964241389 to your computer and use it in GitHub Desktop.
# Do not try this at home…
import turtle
import random
# Starts off fairly "normal"…
n_turtles = 100
window = turtle.Screen()
window.tracer(0)
window.setup(700, 700)
window.bgcolor(0.2, 0.2, 0.2)
# A mammoth list comprehension to create all
# the turtles and set their initial state
cute_turtles = [
(
cute_turtle := turtle.Turtle(),
cute_turtle.left(idx * (360 / n_turtles)),
cute_turtle.color(
random.random(),
random.random(),
random.random(),
),
cute_turtle.penup(),
cute_turtle.shape("turtle"),
)
for idx in range(n_turtles)
]
# Run the animation without a while loop
list(
map(
lambda _: [
cute_turtle.forward(1)
for cute_turtle, *_ in cute_turtles
],
range(30),
)
)
window.update()
turtle.done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment