Search code examples
vectorprocessing

How to reverse vector in openProcessing?


Sorry if this is a very simple problem. How do I make the rect bounce off the side of the Processing window. Im not to sure what the error message means as well "the operator *= is undefined for the argument type(s) PVector int".

PVector position, velocity, scaler, scaleSpeed, blurValue, blurSpeed;
PImage avatar;

void setup()
{
  size(600,600);
  avatar = loadImage("BlackPower.png");
  position = new PVector(0, 0);
  velocity = new PVector(2,0);
}

void draw()
{
  background(255);
  translate(position.x, position.y);
  position.add(velocity);

  fill(0);
  rect(50,50, 200,50);

  if(position.x>width || position.x<0 || 
     position.y>height  || position.y<0)
   {
     velocity*=-1;
   }
}

Solution

  • PVector is not a number, if you want to multiply it with something, use mult() - http://processing.org/reference/PVector.html