Skip to content

Instantly share code, notes, and snippets.

@claiire
Last active April 20, 2017 06:06
Show Gist options
  • Save claiire/4d7262beae8fbc3d231f2227f3f18c30 to your computer and use it in GitHub Desktop.
Save claiire/4d7262beae8fbc3d231f2227f3f18c30 to your computer and use it in GitHub Desktop.
A Processing program that draws a "clock" diagram with concentric rings of integers. Mayb be useful for teaching modular arithmetic to students
"""
Processing 3, with Python 3.
Draws a circle containing 4 concentric rings of numbers, increasing as they move inwards,
so the first ring shows, for draw_clock(12), [0, 11], the second ring shows [12, 24], etc.
This is useful for generating diagrams to help explain modular arithmetic to students.
Think of it like a clock face,and you "wrap around" when you reach the top again.
"""
def to_cart(r, theta):
return (width/2 + r*cos(radians(theta)), width/2 - r*sin(radians(theta)))
def num_ring(n1, n2, r):
fill(0)
for (i,j) in zip(range(n1,n2), range(450, 90, -(360/(n2 - n1)))):
(x, y) = to_cart(r, j)
text(i, x, y)
def draw_clock(n):
size(512, 512)
background(255)
fill(255)
ellipse(width/2, width/2, width, width)
rs = map(lambda x: x/10.0 * width/2, range(8, -2, -2))
for (i,r) in zip(range(n, 5*n, n), rs):
num_ring(i - n, i, r)
draw_clock(12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment