-
-
Save stephengruppetta/0267d36246742748412a8f5c36eb9414 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Do not try this at home… | |
import turtle | |
import random | |
import itertools | |
n_turtles = 100 | |
window = turtle.Screen() | |
window.tracer(0) | |
window.setup(700, 700) | |
window.bgcolor(0.2, 0.2, 0.2) | |
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) | |
] | |
list( | |
map( | |
lambda _: ( | |
[ | |
( | |
cute_turtle.forward(1), | |
cute_turtle.setheading(180 - cute_turtle.heading()) | |
if abs(cute_turtle.xcor()) > window.window_width() / 2 | |
else None, | |
cute_turtle.setheading(-cute_turtle.heading()) | |
if abs(cute_turtle.ycor()) > window.window_height() / 2 | |
else None, | |
) | |
for cute_turtle, *_ in cute_turtles | |
], | |
window.update(), | |
), | |
itertools.cycle([None]), | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment