# \[SOLVED\] PVector in py.processing problem

**URL:** <https://discourse.processing.org/t/solved-pvector-in-py-processing-problem/8306>\
**Category:** Processing.py\
**Created:** [February 11, 2019, 11:45pm UTC](https://discourse.processing.org/t/solved-pvector-in-py-processing-problem/8306 "2019-02-11T23:45:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![warsoldier011](https://avatars.discourse-cdn.com/v4/letter/w/a6a055/32.png) [@warsoldier011](https://discourse.processing.org/u/warsoldier011)\
**Post date:** [February 11, 2019, 11:45pm UTC](https://discourse.processing.org/t/solved-pvector-in-py-processing-problem/8306/1 "2019-02-11T23:45:50Z")

</div>

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](http://Trinket.io) to code in python for processing. Here is the trinket:  
[https://trinket.io/python/a7cb810217](https://trinket.io/python/a7cb810217)

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [February 12, 2019, 12:51am UTC](https://discourse.processing.org/t/solved-pvector-in-py-processing-problem/8306/2 "2019-02-12T00:51:24Z")

</div>

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

```auto
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](https://github.com/nature-of-code/The-Nature-of-Code-Examples-Python).

---

<div class="post-metadata">

**Author:** ![warsoldier011](https://avatars.discourse-cdn.com/v4/letter/w/a6a055/32.png) [@warsoldier011](https://discourse.processing.org/u/warsoldier011)\
**Post date:** [February 12, 2019, 1:56am UTC](https://discourse.processing.org/t/solved-pvector-in-py-processing-problem/8306/3 "2019-02-12T01:56:50Z")

</div>

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.
