LoginSignup
1
1

More than 5 years have passed since last update.

Processing - 08 - バウンドボールの描画(はじめてのベクトル)

Last updated at Posted at 2018-02-05

スクリーンショット 2018-02-05 22.26.09.png

PVector location;
PVector velocity;

void setup(){
  size(1024, 768);    
  frameRate(60);      
  stroke(194,24,91);  
  fill(233,30,99,127);
  location = new PVector(40,40);
  velocity = new PVector(2,5);
}


void draw(){
  background(15);                      
  ellipse(location.x,location.y,20,20);
  location.add(velocity);

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



class PVector{
  float x;
  float y;

  PVector(float x_, float y_){
    x = x_;
    y = y_;
  }

  void add(PVector pvector){
    x = x + pvector.x;
    y = y + pvector.y;
  }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1