--출석: 김정운, 김남윤, 전주영, 유승환,변수홍, 최주영, 김동후, 박상현, 양정애, 김아진, 진다 빈


--주제:저희조는 물리적인 현상을 구현해보자는 제안이 나와 공을 topview에서 본듯한 효과  를 만들어 보았습니다.


PImage ball;
int x,y;
float ballSize;
int stayOnHand;

float a,v,s; // a는 가속도 v는 속도 s 는 높이.
// float t;

void setup(){ 
  size(300,300);
  x=y=150;
  ballSize =50;
  a= -9.8;
  v= 0;
  s = 1000;
  stayOnHand = 1;
 
  ball = loadImage("ball.jpg");
}


void draw(){
  background(255);
 
 if (mousePressed == true ){
    if (stayOnHand != 0) stayOnHand = 0;
    else if (stayOnHand == 0) {v=-100;}
     dribble();
    }
 
  if (stayOnHand == 1){
    x= mouseX;
    y= mouseY;
   
  }else if (stayOnHand == 0){
    if (s<=0 ){v=-v-5;s=0;} // 공이땅에 닿은 경우 속도가 reverse, 이때 -5는 마찰에 의한 자연 감속
   // t = t+0.001;
   {
     v = v+ a;
    s = s + v;
   }
  }
 
 ballSize = s/10+10; 
 image(ball, x-(ballSize/2),y-(ballSize/2), ballSize, ballSize); 
}

void dribble(){
  if (mouseX < x && mouseX > x-ballSize/2){x=x+2;}
  if (mouseX > x && mouseX < x+ballSize/2){x=x-2;}
  if (mouseY < y && mouseY > y-ballSize/2){y=y+2;}
  if (mouseY > x && mouseY < y+ballSize/2){y=y-2;}
 
}
ball



-----------------------------------------------------------------------------------

수업중에 한것

 PImage ball;
 boolean isItOnHand;
 int x,y;
 
 float a,v,s;
 float ballSize;

void setup(){
  size(600,600);
  x=y= 300;
  isItOnHand = true;
  a = -9.8;
  v = 0;
  s = 1000;
  ballSize = 110;
  ball = loadImage("ball.jpg");
}

void draw(){
  background(255);
 
  if (mousePressed == true){
    if (isItOnHand == true) isItOnHand = false;
    else{
      if (mouseX >x-ballSize/2 && mouseX < x+ballSize/2)
        if (mouseY >y-ballSize/2 && mouseY < y+ballSize/2)
        dribble();
    }
  }
  
  if (isItOnHand == true){
    x = mouseX;// 마우스 따라 움직임
    y = mouseY;
  }else{
 
    if (s <= 0){v = -v-5;s= 0;}
    v = v + a;
    s = s + v;
    ballSize = s/10+10;
  
    // 공의 높이 계산
  }
 
  image(ball,x-(ballSize/2),y-(ballSize/2),ballSize,ballSize);
 
}

void dribble(){
  v = -100;
  if (mouseX < x && mouseX > x-ballSize/2) x = x+2;
  if (mouseX > x && mouseX < x+ballSize/2) x = x-2;
  if (mouseY < y && mouseY > y-ballSize/2) y = y+2;
  if (mouseY > y && mouseY < y+ballSize/2) y = y-2;
}

Posted by 알 수 없는 사용자