Skip to content

Instantly share code, notes, and snippets.

@oolong32
Last active February 15, 2017 20:37
Show Gist options
  • Save oolong32/6555ca97408abbd37c8a0ca4dc080472 to your computer and use it in GitHub Desktop.
Save oolong32/6555ca97408abbd37c8a0ca4dc080472 to your computer and use it in GitHub Desktop.
newPage(1000, 1000)
# grid is defined by dimension of a single cell
cell = 80
rows = int(height() / cell)
cols = int(width() / cell)
offset_x = width() % cell / 2
offset_y = height() % cell / 2
translate(offset_x, offset_y)
pi_2 = 2*pi
rad = cell * 0.45
for row in range(rows):
for col in range(cols):
for a in range(int(100*pi_2)):
save()
fill(0)
# move to center of single cell
translate(col*cell + cell/2, row*cell + cell/2)
rx = cos(row * a)
ry = cos(col * a)
x = cos(a) * rad * rx
y = sin(a) * rad * ry
oval(x-0.5, y-0.5, 1, 1)
fill(None)
stroke(.25)
# rect(-cell/2, -cell/2, cell, cell)
restore()
# accepts other filetypes, e.g. '.pdf'
saveImage('~/Desktop/roses.jpg')
@oolong32
Copy link
Author

See Daniel Shiffman’s Coding Challenge #55: ‘Mathematical Rose Patterns’.
Script will work in DrawBot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment