Skip to content

Commit

Permalink
Merge pull request #138 from villares/pvector-helper-transcrypt-mode
Browse files Browse the repository at this point in the history
Adding PVector alias to createVector() and p5.Vector class method aliases
  • Loading branch information
berinhard authored Apr 17, 2021
2 parents a1fe34c + b92e409 commit dd440ea
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pyp5js/pyp5js.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,25 @@ def pop(*args):
pushMatrix = push
pushStyle = push

# PVector is a helper/alias to create p5.Vector objects
def PVector(x=0, y=0, z=0):
return _P5_INSTANCE.createVector(x, y, z)
# aliases for p5.Vector class methods
setattr(PVector, 'dist', p5.Vector.dist)
setattr(PVector, 'add', p5.Vector.add)
setattr(PVector, 'sub', p5.Vector.sub)
setattr(PVector, 'mult', p5.Vector.mult)
setattr(PVector, 'div', p5.Vector.div)
setattr(PVector, 'dot', p5.Vector.dot)
setattr(PVector, 'cross', p5.Vector.cross)
setattr(PVector, 'lerp', p5.Vector.lerp)
setattr(PVector, 'random2D', p5.Vector.random2D)
setattr(PVector, 'random3D', p5.Vector.random3D)
setattr(PVector, 'angleBetween', p5.Vector.angleBetween)
setattr(PVector, 'fromAngle', p5.Vector.fromAngle)
setattr(PVector, 'fromAngles', p5.Vector.fromAngles)
setattr(PVector, 'equals', p5.Vector.equals)

def pre_draw(p5_instance, draw_func):
"""
We need to run this before the actual draw to insert and update p5 env variables
Expand Down

0 comments on commit dd440ea

Please sign in to comment.