Subscribed unsubscribe Subscribe Subscribe

Ex_01_01_Ball

not use PVector

float x = 100;
float y = 100;
float xSpeed = 2.1;
float ySpeed = 3.9;

void setup(){
  size(600,600);
  background(255);
}

void draw(){
  x = x + xSpeed;
  y = y + ySpeed;
  
  if ((x<0)||(width<x)){
    xSpeed = xSpeed * -1;
  }
  if ((y<0)||(height<y)){
    ySpeed = ySpeed * -1;
  }
  
  fill(255,32);
  rect(0,0,width,height);
  
  fill(0);
  ellipse(x,y,30,30);
  
  println(x,y); // ellipse center XY is float !?
}