2023年11月23日 星期四

week11咻消失

week11

week11_1_random_seat 
void setup(){
  size(600,400);
}
void draw(){
  background(255);
  for(int i=0;i<5;i++){
   for(int j=0;j<6;j++){
     rect(j*100,i*100,100,100);
   }
  }
}
void setup(){
  size(600,500);
}
void draw(){
  background(255);
  for(int i=0;i<4;i++){
   for(int j=0;j<6;j++){
     fill(#F5B4B4); rect(j*100,i*100,100,100);
     fill(0); text("Hello",j*100+25,i*100+50);
   }
  }
}
week11_2_random_seat_array_value
void setup(){
  size(600,500);
  for(int i=0;i<4;i++){
    for(int j=0;j<6;j++){
      value[i][j] = int (random(40));
    }
  }
}
int [][]value = new int [4][6];
void draw(){
  background(255);
  for(int i=0;i<4;i++){
   for(int j=0;j<6;j++){
     fill(#F5B4B4); rect(j*100,i*100,100,100);
     fill(0); text(value[i][j],j*100+25,i*100+50);
   }
  }
}
week11_3_random_seat_array_value_swap
void setup(){
  size(600,500);
  for(int i=0;i<4;i++){
    for(int j=0;j<6;j++){
      value[i][j] = i*6+j+10; //從10開始,數字不重複
    }
  }
  for(int k=0;k<2;k++){ //隨機挑兩個數字交換
    int i=int(random(4)), j=int(random(6));
    int i2=int(random(4)) , j2=int(random(6));
    int temp = value[i][j];
    value[i][j] = value[i2][j2];
    value[i2][j2] = temp;
  }
}
int [][]value = new int [4][6];
void draw(){
  background(255);
  for(int i=0;i<4;i++){
   for(int j=0;j<6;j++){
     fill(#F5B4B4); rect(j*100,i*100,100,100);
     fill(0); text(value[i][j],j*100+25,i*100+50);
   }
  }
}
week11_4_many_states
int state = 0; //0:white, 1:red, 2:blue
void setup(){
  size(400,400);
  textSize(50);
}
void draw(){
  if(state==0){//第0關,白色
    background(255);
    fill(0);text("Click to Start",80,200);
  }else if(state==1){ //第1關,紅色
    background(255,0,0);
  }else if(state==2){ //第2關,藍色
    background(0,0,255);
  }
} 不能切換場景
week11_5_many_states_mousePressed
int state = 0; //0:white, 1:red, 2:blue
void setup(){
  size(400,400);
  textSize(50);
}
void draw(){
  if(state==0){//第0關,白色
    background(255);
    fill(0);text("Click to Start",80,200);
  }else if(state==1){ //第1關,紅色
    background(255,0,0);
  }else if(state==2){ //第2關,藍色
    background(0,0,255);
  }
}
void mousePressed(){
  if(state==0) state=1;
}
可以切換場景了
week11_6_many_states_mousePressed_keyPressed
int state = 0; //0:white, 1:red, 2:blue
void setup(){
  size(400,400);
  textSize(50);
}
int x=50, y=50;
void draw(){
  if(state==0){//第0關,白色
    background(255);
    fill(0);text("Click to Start",80,200);
  }else if(state==1){ //第1關,紅色
    background(255,0,0);
    fill(255); rect(300,50,50,50);
    fill(128); rect(x,y,50,50);
  }else if(state==2){ //第2關,藍色
    background(0,0,255);
  }
}
void mousePressed(){
  if(state==0) state=1;
}
void keyPressed(){
  if(state==1 && keyCode==RIGHT){
    x+=10;
    if(x==300) state=2;
  }
}
達成換場景條件,換下一個場景
week11_7_many_states_mousePressed_keyPressed_mills_t_60
int state = 0; //0:white, 1:red, 2:blue
void setup(){
  size(400,400);
  textSize(50);
}
int x=50, y=50, t=100;
void draw(){
  if(state==0){//第0關,白色
    background(255);
    fill(0);text("Click to Start",80,200);
    x=50;
    if(t==0) state=0;
  }else if(state==1){ //第1關,紅色
    background(255,0,0);
    fill(255); rect(300,50,50,50);
    fill(128); rect(x,y,50,50);
    t=100;
  }else if(state==2){ //第2關,藍色(倒數10秒)
    background(0,0,255);
    fill(255,255,0); text("Wait "+t,80,200);
    t--;
    if(t==0) state=0;
  }
}
void mousePressed(){
  if(state==0) state=1;
}
void keyPressed(){
  if(state==1 && keyCode==RIGHT){
    x+=10;
    if(x==300) state=2;
  }
}
倒數10秒後重新開始
week11_8_basketball_shoot_curve
PImage imgRack;
void setup(){
  size(300,300);
  imgRack = loadImage("rack.png");
}
void draw(){
  background(255);
  image(imgRack,0,0);
  if(mousePressed){
    fill(255); ellipse(posX,posY,20,20);
    line(posX,posY,mouseX,mouseY);
    fill(#FFA652); ellipse(mouseX,mouseY,20,20);
  }
}
float posX=-100, posY=-100;
void mousePressed(){
  posX = mouseX;
  posY = mouseY;
}
week11_9_basketball_shoot_curve2 PImage imgRack; void setup(){   size(300,300);   imgRack = loadImage("rack.png"); } void draw(){   background(255);   image(imgRack,0,0);   if(flying){     x += vx;     y += vy;   }else{     x = mouseX;     y= mouseY;     if(mousePressed){       fill(255); ellipse(posX,posY,20,20);       line(posX,posY,mouseX,mouseY);     }   }    fill(#FFA652); ellipse(x,y,20,20); } boolean flying = false; float x,y,vx,vy; float posX=-100, posY=-100; void mousePressed(){   x=posX = mouseX;   y=posY = mouseY;   flying = false; } void mouseReleased(){   vx = posX-mouseX;   vy = posY-mouseY;   flying = true; }
week11_B_mine_sweep
void setup(){
  size(600,400);
}
float x=300, y=200, dir=0;
void draw(){
    //background(0);
    joker(x,y,dir);
    x+= cos(dir);
    y+= sin(dir);
}
void joker(float x,float y,float dir){
  ellipse(x,y,50,50);
  line(x, y, x+25*cos(dir), y+25*sin(dir) ); 
} 
void keyPressed(){
  if(keyCode==RIGHT) dir +=0.1;
  if(keyCode==LEFT) dir -=0.1;
}







沒有留言:

張貼留言