[SOLVED] PVector in py.processing problem

Hello there, I’ve currently run into a problem using PVector’s in py.processing. I’m trying to make a bouncing ball program using PVectors instead of plain old x, y , xspeed, yspeed, etc. However, when I try to add the current pos to the velocity nothing happens. I don’t know if it’s my code or the PVector module itself. By the way I am using Trinket.io to code in python for processing. Here is the trinket:
https://trinket.io/python/a7cb810217

1 Like

Couple different ways to fix this. This is one solution:

from processing import *

class ball(object):
  def __init__(self, xpos, ypos):
    self.pos = PVector(xpos, ypos)
    
  def move(self):
    vel = PVector(2,3)
    self.pos.add(vel)

  def display(self):
    stroke(4)
    fill(255)
    ellipse(self.pos.x, self.pos.y, 12, 12)

Daniel Shiffman’s Nature of Code covers this stuff in Java Processing. If you’re looking for Python implementations, there’s this repo: The-Nature-of-Code-Examples-Python.

2 Likes

Thank you, very much. I see that I was referencing self.xpos and self.ypos instead of the actual PVector variable pos. Also, thank you for the python implementations, it’s extremely helpful.

1 Like