Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable a PVector interfacea as in Processing Python Mode #125

Closed
berinhard opened this issue Jul 20, 2020 · 6 comments
Closed

Enable a PVector interfacea as in Processing Python Mode #125

berinhard opened this issue Jul 20, 2020 · 6 comments

Comments

@berinhard
Copy link
Owner

This issue was created after #114 and the object is to have a PVector implementation as described by Processing's docs.

A possible approach is to add a PVector method to the pyp5js/pyp5js.py file to work a proxy for the p5.Vector implementation. Something similar to:

def PVectorAdd(c1, c2):
    return _P5_INSTANCE.Vector.add(c1, c2)

def PVector(x, y):
    return _P5_INSTANCE.createVector(x, y)

PVector.add = PVectorAdd
@villares
Copy link
Contributor

villares commented Nov 8, 2020

Trying my hand on a wrapper here:
https://gist.github.com/villares/e639a34eef756beba2f79a55203cd51e

@villares
Copy link
Contributor

villares commented Nov 9, 2020

@villares
Copy link
Contributor

villares commented Nov 10, 2020

Hi @berinhard, as in Transcrypt we won't get the operator overloading, what do you think of a very thin helper layer for p5.Vector using the PVector names?

Something like this:

from pyp5js import *

def setup():
    createCanvas(200, 200)
    background(160)

def draw():
    fill("blue")
    background(200)
    radius = sin(frameCount / 60) * 50 + 50
    
    v = PVector(100, 100)
    v.div(2)
    ellipse(v.x, v.y, radius, radius)
    v.add(30, 30)
    ellipse(v.x, v.y, radius, radius)
    w = PVector.add(v, PVector(50,0))
    ellipse(w.x, w.y, radius, radius)
    z = PVector.div(w, 2)
    ellipse(z.x, z.y, radius, radius)

def PVector(x=0, y=0, z=0):
    return createVector(x, y, z)

# only the class methods need aliases!
PVector.dist = p5.Vector.dist
PVector.add = p5.Vector.add
PVector.sub = p5.Vector.sub
PVector.mult = p5.Vector.mult
PVector.div = p5.Vector.div
PVector.dot = p5.Vector.dot
PVector.cross = p5.Vector.cross
PVector.lerp = p5.Vector.lerp
PVector.random2D = p5.Vector.random2D
PVector.random3D = p5.Vector.random3D
PVector.angleBetween = p5.Vector.angleBetween
PVector.fromAngle = p5.Vector.fromAngle
PVector.fromAngles = p5.Vector.fromAngles
PVector.equals = p5.Vector.equals

@berinhard
Copy link
Owner Author

This set of aliases is extremely valid IMHO! Give it a try @villares and I hope it'll work =)

@berinhard
Copy link
Owner Author

@villares don't know if this can help you, but here's how we're setting attrs to isolate python functions such as map, set and filter: https://github.com/berinhard/pyp5js/blob/develop/pyp5js/python_functions.py

@berinhard
Copy link
Owner Author

Fixed by #137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants