Last active
December 2, 2015 15:59
-
-
Save akiross/f1d4c307372b5a16278e to your computer and use it in GitHub Desktop.
Waving circles (atoms?) with turtle
This file contains 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
#!/usr/bin/env python3 | |
import turtle as t | |
from collections import defaultdict | |
# Parameters | |
count = 10 | |
spacing = 25 | |
radius = 0.3 | |
step_rot = 3 | |
step_fw = 1 | |
initang = lambda i, j: 10 * (i + j) | |
bx, by = 80, 80 | |
# Code | |
cw, ch = 400, 400 | |
t.setup(cw, ch) | |
t.setworldcoordinates(0, 0, cw, ch) | |
t.tracer(0, 0) | |
balls = defaultdict(lambda: dict()) | |
for i in range(count): | |
for j in range(count): | |
b = t.Turtle() | |
b.speed(0) | |
b.penup() | |
b.shape('circle') | |
b.shapesize(radius, radius, radius) | |
b.goto(bx + i * spacing, by + j * spacing) | |
for x in range(initang(i, j)): | |
b.forward(step_fw) | |
b.left(step_rot) | |
b.pendown() | |
balls[i][j] = b | |
while True: | |
for i in range(count): | |
for j in range(count): | |
balls[i][j].forward(step_fw) | |
balls[i][j].left(step_rot) | |
t.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment