Skip to content

Instantly share code, notes, and snippets.

@tildebyte
Created June 23, 2014 20:17
Show Gist options
  • Save tildebyte/8acc620acfe24bdc8a03 to your computer and use it in GitHub Desktop.
Save tildebyte/8acc620acfe24bdc8a03 to your computer and use it in GitHub Desktop.
HMagneticField example converted to Processing's Python mode.
add_library('HYPE')
field = None
def setup():
size(640, 640)
H.init(this).background(0xFF202020)
smooth()
colors = HColorPool([0xFFFFFFFF, 0xFFF7F7F7,
0xFFECECEC, 0xFF343434,
0xFF0095a8, 0xFF000616,
0xFFFF3300, 0xFFFF6600]).fillOnly()
field = HMagneticField()\
.addMagnet(width / 4,
height / 4,
width * 3/4,
height * 3/4)
pool = HDrawablePool(930)\
.autoAddToStage()\
.add(
HRect()
.rounding(2)
.size(5, 15)
.anchorAt(H.CENTER)
)\
.layout(
HGridLayout()
.startX(5)
.startY(15)
.spacing(21, 21)
.cols(31)
)\
.colorist(colors)\
.onCreate(DrawableCallback())\
.requestAll()
def draw():
m = field.magnet(0)
m.northx = mouseX
m.northy = mouseY
H.drawStage()
class DrawableCallback(HCallback):
def run(self, hrect):
hrect.noStroke()
field.addTarget(hrect)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment