Processing - 08 - 경계 공 그리기 (처음 벡터)

5254 단어 processing

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;
  }
}

좋은 웹페이지 즐겨찾기