Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lotus Rosettes for Processing Python Mode
"""
Under Creative Commons License
https:#creativecommons.org/licenses/by-sa/4.0/
Ported for Processing Python Mode py.processing.org <- for Processing IDE
by Alexandre Villares abav.lugaralgum.com, 9-Oct-2018
Based upon code for p5js.org at https://jcponce.github.io/misc/lotusrosettes.html
by Juan Carlos Ponce Campuzano, 9-Oct-2018
Based upon Dan Anderson's code
https:#www.openprocessing.org/sketch/519299
"""
gridsize = 13
def setup():
size(550, 550)
colorMode(HSB)
def draw():
background(0)
gridsize = int(map(mouseX, 0, width, 4, 13))
textAlign(LEFT, CENTER)
stroke(0, 0, 80)
fill(0, 0, 80)
#text("r=asin(cos(a/b * t))", 6, 0 + width / (2 * gridsize))
textAlign(CENTER, CENTER)
text("a", width / 2, height / (6 * gridsize))
text("b", width / (6 * gridsize), height / 2)
for a in range(1, gridsize+1):
for b in range(1, gridsize+1):
cx = map(a, 1, gridsize, 0 + width / gridsize, width - width / gridsize)
cy = map(b, gridsize, 1, height - height / gridsize, 0 + height / gridsize)
if (a == 1):
text(str(b), cx - width / (1.4 * gridsize), cy)
text(str(b), cy, cx - height / (1.4 * gridsize))
r = 0.25 * width / (gridsize + 1)
beginShape()
noFill()
t = 0
ox = cx + r * asin(cos(1.0 * a / b * t)) * cos(t)
oy = cy + r * asin(cos(1.0 * a / b * t)) * sin(t)
done = False
while t < 4 * gridsize * TWO_PI and not done:
x = cx + r * asin(cos(1.0 * a / b * t)) * cos(t)
y = cy + r * asin(cos(1.0 * a / b * t)) * sin(t)
stroke(cx, cy, 255)
vertex(x, y)
if ((abs(x - ox) + abs(y - oy) < 0.05) and (t > TWO_PI / 150)):
done = True
t += TWO_PI / 300
endShape(OPEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.