2019年10月3日 星期四

喬 的 無 形 壓 力 日 Week4

牛頓運動

左右滾















int ballX=300, ballY=300;
int vx=-2;
void setup() {
  size(700, 400);
}
void draw() {
  background(255);
  ellipse(ballX, ballY, 30, 30);
  ballX +=vx;

  if (ballX<0) vx =+2;
  if (ballX>700) vx =-2;
}

int ballX=300, ballY=300;
int vx=-2, vy=+2;
void setup() {
  size(700, 400);
}
void draw() {
  background(255);
  ellipse(ballX, ballY, 30, 30);
  ballX +=vx;
  ballY +=vy;
  if (ballX<0 +15) vx =+2;  ///原本是球的圓心在框框內
  if (ballX>700 -15) vx =-2;   ///+-15  球的邊緣在框框內
  if(ballY<0 +15) vy =+2;
  if(ballY>400 -15) vy =-2
}

紀錄路徑




































float ballX=300, ballY=300;
float vx=-2, vy=-10;
void setup() {
  size(600, 400);
}
void draw() {
  //background(255);
  ellipse(ballX, ballY, 30, 30);
  ballX +=vx;
  ballY +=vy; println(vy);
  vy += 0.98;
  if (ballX<0 +15)      vx= -vx*0.9;
  if (ballX>700 -15)    vx= -vx*0.9;
  if (ballY<0 +15)      vy= -vy*0.9;
  if (ballY>400 -15)    vy= -vy*0.9;
}

































float ballX=300, ballY=300;
float vx=-2, vy=-10;
void setup() {
  size(600, 400);
}
void draw() {
  //background(255);
  ellipse(ballX, ballY, 30, 30);
  ballX +=vx;
  ballY +=vy; println(vy);
  vy += 0.98;
  if (ballX<0 +15)      vx= -vx*0.9;
  if (ballX>700 -15)    vx= -vx*0.9;
  if (ballY<0 +15)      vy= -vy*0.9;
  if (ballY>400 -15){
    vy = -vy+0.9;
    vx = vx*0.9;
    ballY=400-15;
  }
  vy +=0.98;
}

馬力歐
































PImage imgMario;
float marioX=100 , marioY=100;
float marioVX=0 , marioVY=0;
void setup() {
  size(500, 500);
  imgMario = loadImage("mario.png");
}
void draw() {
  //background(255); ///背景
  rect(0, 200, 500,50); ///樓梯
  image(imgMario, marioX, marioY, 100, 100);
  marioX +=marioVX;
  marioY +=marioVY;
  if(marioY<=100) marioVY +=0.9;
  else marioY = 100; ///hold on floor
}
void keyPressed(){
  if(keyCode==RIGHT) marioX+=3;
  if(keyCode==LEFT)  marioX-=3;
  if(keyCode==UP){
    marioVY = -15;
  }
}

















PImage imgMario;
float marioX=100 , marioY=100;
float marioVX=0 , marioVY=0;
void setup() {
  size(500, 500);
  imgMario = loadImage("mario.png");
}
void draw() {
  background(255);
  rect(0, 200, 500,50);  ///樓梯

  image(imgMario, marioX, marioY, 100, 100);
  marioX +=marioVX;
  marioY +=marioVY;
  if(softBrake==1) marioVX *=0.9;
  if(marioY<=100) marioVY +=0.9;
  else marioY = 100; ///hold on floor
}
int softBrake=0;
void keyReleased(){
  if(keyCode==RIGHT) softBrake=1;
  if(keyCode==LEFT)  softBrake=1;
}
void keyPressed(){
  if(keyCode==RIGHT){
    marioVX=3; ///marioX+=3;
    softBrake=0;
  }else if(keyCode==LEFT){
    marioVX=-3; ///marioX-=3;
    softBrake=0;
  }else if(keyCode==UP){
    marioVY = -15;
  }
}