Skip to content

Instantly share code, notes, and snippets.

@tildebyte
Created June 23, 2014 16:09
Show Gist options
  • Save tildebyte/502a827478c936f46996 to your computer and use it in GitHub Desktop.
Save tildebyte/502a827478c936f46996 to your computer and use it in GitHub Desktop.
Conversion of first HYPE example to Processing's Python mode.
add_library('hype')
def setup():
size(640, 640)
H.init(this).background(36)
smooth()
rect1 = HRect(100)
rect1.rounding(10) # set corner rounding
rect1.fill(255, 102, 0) # set fill color
rect1.stroke(0, 150) # set stroke color and alpha
rect1.strokeWeight(6) # set stroke weight
# set where anchor point is / key point for rotation and positioning
rect1.anchorAt(H.CENTER)
rect1.rotation(45) # set rotation of the rect
rect1.loc(100, height / 2) # set x and y location
H.add(rect1)
# here's the same code / with method chaining
rect2 = HRect(100)
rect2.rounding(10)\
.fill(255, 153, 0)\
.stroke(0, 150)\
.strokeWeight(6)\
.anchorAt(H.CENTER)\
.rotation(45)\
.loc(247, height / 2)
H.add(rect2)
# here's the same code / minus the hard returns and tabbing
rect3 = HRect(100)
rect3.rounding(10).fill(255, 204, 0).stroke(0, 150).strokeWeight(6).anchorAt(H.CENTER).rotation(45).loc(394, height / 2)
H.add(rect3)
H.drawStage() # paint the stage
# here is the non HYPE version / basic processing syntax
with pushMatrix():
fill(255, 51, 0)
stroke(0, 150)
strokeWeight(6)
translate(width - 100, (height / 2))
rotate(radians(45))
rect(0, 0, 100, 100, 10, 10, 10, 10)
"""
thoughts: well in the processing version you'd have to use push and
pop matrix to perform the rotation and positioning. I find this
difficult to explain to designers that you're not rotating the rect
but the entire stage.
not having the ability to adjust an "anchor" position means we have to
calculate the rect's y coordinate to get it centered so trying to
subract half of the rect's height
translate(width - 100, (height / 2) - 50) # nope still doesn't center
this is because a 100 x 100 rectangle rotated 45 degrees now sits at
141 x 141 (approx) this would mean we'd have to offset like so:
translate(width - 100, (height / 2) - 70.5)
"""
# draw where the horiz line is
stroke(0, 149, 168)
strokeWeight(1)
line(0, height / 2, width, height / 2)
noLoop()
def draw():
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment