2023年10月5日 星期四

部落格Week04

第一堂課



  • 輸入程式碼做出格子(格子是為了牌作準備)


void setup(){
  size(400,400);
}
int [][]card=new int[8][11];
void draw(){
  background(255);
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      rect(j*32,i*50,32,50);
    }
  } 
 } 

  • 去開小畫家去吸UNO的顏色並記錄色碼



  • 新增檔案輸入程式碼幫牌填色


void setup(){
  size(400,400);
}
int [][]card=new int[8][11];
color[]c={#FF5555,#FFAA00,#55AA55,#5555FF};
void draw(){
  background(255);
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      fill(c[i%4]);
      rect(j*32,i*50,32,50);
    }
  } 
 }

  •  新增檔案修改程式碼,繼續捏牌

 

  •  繼續修改程式碼讓牌更好看


void setup(){
  size(400,400);
}
int [][]card=new int[8][11];
color[]c={#FF5555,#FFAA00,#55AA55,#5555FF};
void draw(){
  background(255);
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      drawCard(j*32,i*50,c[i%4]);
    }
  } 
 }
 void  drawCard(int x, int y, color c){
   stroke(128);
   fill(255);
   rect(x,y,32,50,7);
   noStroke();
   fill(c);
   rect(x+3,y+3,32-5,50-5,4);
 }

 

  •  開新檔案輸入程式碼讓牌有中間的橢圓



void setup(){
  size(400,400);
}
int [][]card=new int[8][11];
color[]c={#FF5555,#FFAA00,#55AA55,#5555FF};
void draw(){
  background(255);
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      drawCard(j*32,i*50,c[i%4]);
    }
  } 
 }
 void  drawCard(int x, int y, color c){
   stroke(128);
   fill(255);
   rect(x,y,32,50,7);
   noStroke();
   fill(c);
   rect(x+3,y+3,32-5,50-5,4);

   pushMatrix();
   fill(255);
   translate(x+16,y+25);
   rotate(radians(45));
   ellipse(0,0,20,30);
   popMatrix();
 }

第二堂課


  •  開新檔案輸入程式碼讓橢圓的中間跟旁邊有數字顯示

  •  修改程式碼讓數字變為0到10

         

void setup(){
  size(400,400);
}
int [][]card=new int[8][11];
color[]c={#FF5555,#FFAA00,#55AA55,#5555FF};
void draw(){
  background(255);
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      drawCard(j*32,i*50,c[i%4],j);
    }
  } 
 }
 void  drawCard(int x, int y, color c,int n){
   stroke(128);
   fill(255);
   rect(x,y,32,50,7);
   noStroke();
   fill(c);
   rect(x+3,y+3,32-5,50-5,4);
   
   pushMatrix();
   fill(255);
   translate(x+16,y+25);
   rotate(radians(45));
   ellipse(0,0,20,30);
   popMatrix();
   
  textSize(9);
   textAlign(CENTER,CENTER);
   text(""+n,x+7,y+6);
   
   textSize(20);
   fill(c);
   text(""+n,x+16,y+22);
 }

  •  開新檔案輸入程式碼,顏色怪怪的

  •   修改程式碼讓牌變彩色的

         

  •    修改程式碼讓牌會互換(洗牌)

        


void setup(){
  size(400,400);
  myShuffle();
}
void myShuffle(){
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      cardN[i*11+j]=j;
      cardC[i*11+j]=C[i%4];
    }
  }
int a=int(random(88)),b=int(random(88));
int temp=cardN[a];
cardN[a]=cardN[b];
cardN[b]=temp;
temp=cardC[a];
cardC[a]=cardC[b];
cardC[b]=temp;
}
int []cardN=new int[88];
int []cardC=new int[88];
color[]C={#FF5555,#FFAA00,#55AA55,#5555FF};
void draw(){
  background(255);
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      drawCard(j*32,i*50,cardC[i*11+j],cardN[i*11+j]);
    }
  } 
 }
 void  drawCard(int x, int y, color c,int n){
   stroke(128);
   fill(255);
   rect(x,y,32,50,7);
   noStroke();
   fill(c);
   rect(x+3,y+3,32-5,50-5,4);
   
   pushMatrix();
   fill(255);
   translate(x+16,y+25);
   rotate(radians(45));
   ellipse(0,0,20,30);
   popMatrix();
   
  textSize(9);
   textAlign(CENTER,CENTER);
   text(""+n,x+7,y+6);
   
   textSize(20);
   fill(c);
   text(""+n,x+16,y+22);
 }

  • 新增檔案修改程式碼用迴圈洗牌(洗得更乾淨)


void setup(){
  size(400,400);
  myShuffle();
}
void myShuffle(){
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      cardN[i*11+j]=j;
      cardC[i*11+j]=C[i%4];
    }
  }
  
for(int i=0;i<10000;i++){
int a=int(random(88)),b=int(random(88));
int temp=cardN[a];
cardN[a]=cardN[b];
cardN[b]=temp;
temp=cardC[a];
cardC[a]=cardC[b];
cardC[b]=temp;
}
}
int []cardN=new int[88];
int []cardC=new int[88];
color[]C={#FF5555,#FFAA00,#55AA55,#5555FF};
void draw(){
  background(255);
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      drawCard(j*32,i*50,cardC[i*11+j],cardN[i*11+j]);
    }
  } 
 }
 void  drawCard(int x, int y, color c,int n){
   stroke(128);
   fill(255);
   rect(x,y,32,50,7);
   noStroke();
   fill(c);
   rect(x+3,y+3,32-5,50-5,4);
   
   pushMatrix();
   fill(255);
   translate(x+16,y+25);
   rotate(radians(45));
   ellipse(0,0,20,30);
   popMatrix();
   
  textSize(9);
   textAlign(CENTER,CENTER);
   text(""+n,x+7,y+6);
   
   textSize(20);
   fill(c);
   text(""+n,x+16,y+22);
 }

第三堂課 

  • 新增檔案並修改程式碼,做出一個放大版的牌

 

void setup(){
  size(800,400);
  myShuffle();
}
void myShuffle(){
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      cardN[i*11+j]=j;
      cardC[i*11+j]=C[i%4];
    }
  }
  
for(int i=0;i<10000;i++){
int a=int(random(88)),b=int(random(88));
int temp=cardN[a];
cardN[a]=cardN[b];
cardN[b]=temp;
temp=cardC[a];
cardC[a]=cardC[b];
cardC[b]=temp;
}
}
int []cardN=new int[88];
int []cardC=new int[88];
color[]C={#FF5555,#FFAA00,#55AA55,#5555FF};
void draw(){
  background(255);
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      drawCard(j*32,i*50,cardC[i*11+j],cardN[i*11+j],32);
    }
  } 
  drawCard(450,50,cardC[7],cardN[77],128);
 }
 void  drawCard(int x, int y, color c,int n,int w){
   float s=w/32.0;
   stroke(128);
   fill(255);
   rect(x,y,32*s,50*s,7*s);
   noStroke();
   fill(c);
   rect(x+2.5*s,y+2.5*s,32*s-5*s,50*s-5*s,4*s);
   
   pushMatrix();
   fill(255);
   translate(x+16*s,y+25*s);
   rotate(radians(45));
   ellipse(0,0,20*s,30*s);
   popMatrix();
   
  textSize(9*s);
   textAlign(CENTER,CENTER);
   text(""+n,x+7*s,y+6*s);
   
   textSize(20*s);
   fill(c);
   text(""+n,x+16*s,y+22*s);
 } 


  •  開新檔案修改程式碼可以用滑鼠左鍵點擊叫出牌

void setup(){
  size(800,400);
  myShuffle();
}
void myShuffle(){
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      cardN[i*11+j]=j;
      cardC[i*11+j]=C[i%4];
    }
  }
  
for(int i=0;i<10000;i++){
int a=int(random(88)),b=int(random(88));
int temp=cardN[a];
cardN[a]=cardN[b];
cardN[b]=temp;
temp=cardC[a];
cardC[a]=cardC[b];
cardC[b]=temp;
}
}
int []cardN=new int[88];
int []cardC=new int[88];
color[]C={#FF5555,#FFAA00,#55AA55,#5555FF};
void draw(){
  background(255);
  if (mousePressed&&mouseButton==RIGHT){
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      drawCard(j*32,i*50,cardC[i*11+j],cardN[i*11+j],32);
    }
  } 
 }else drawCard(50,50,#000000,99,128);
 for(int i=0;i<myCard;i++){
   drawCard(430+40*i,50,cardC[i],cardN[i],128);
 }
}
 int myCard=0;
 void mousePressed(){
   if(mouseButton==LEFT)myCard++;
 }
 void  drawCard(int x, int y, color c,int n,int w){
   float s=w/32.0;
   stroke(128);
   fill(255);
   rect(x,y,32*s,50*s,7*s);
   noStroke();
   fill(c);
   rect(x+2.5*s,y+2.5*s,32*s-5*s,50*s-5*s,4*s);
   
   pushMatrix();
   fill(255);
   translate(x+16*s,y+25*s);
   rotate(radians(45));
   ellipse(0,0,20*s,30*s);
   popMatrix();
   
  textSize(9*s);
   textAlign(CENTER,CENTER);
   text(""+n,x+7*s,y+6*s);
   
   textSize(20*s);
   fill(c);
   text(""+n,x+16*s,y+22*s);
 }

  •  新增檔案修改程式碼根據餘數使牌出現在不同位置(模擬四個玩家)


void setup(){
  size(800,800);
  myShuffle();
}
void myShuffle(){
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      cardN[i*11+j]=j;
      cardC[i*11+j]=C[i%4];
    }
  }
  
for(int i=0;i<10000;i++){
int a=int(random(88)),b=int(random(88));
int temp=cardN[a];
cardN[a]=cardN[b];
cardN[b]=temp;
temp=cardC[a];
cardC[a]=cardC[b];
cardC[b]=temp;
}
}
int []cardN=new int[88];
int []cardC=new int[88];
color[]C={#FF5555,#FFAA00,#55AA55,#5555FF};
void draw(){
  background(255);
  if (mousePressed&&mouseButton==RIGHT){
  for(int i=0;i<8;i++){
    for(int j=0;j<11;j++){
      drawCard(j*32,i*50,cardC[i*11+j],cardN[i*11+j],32);
    }
  } 
 }else drawCard(50,50,#000000,99,128);
 for(int i=0;i<myCard;i++){
   if (i%4==0)drawCard(430+40*i/4,50,cardC[i],cardN[i],128);
   if (i%4==1)drawCard(630-40+40*i/4,350,cardC[i],cardN[i],128);
   if (i%4==2)drawCard(430-80+40*i/4,650,cardC[i],cardN[i],128);
   if (i%4==3)drawCard(230-120+40*i/4,350,cardC[i],cardN[i],128);
 }
}
 int myCard=0;
 void mousePressed(){
   if(mouseButton==LEFT)myCard++;
 }
 void  drawCard(int x, int y, color c,int n,int w){
   float s=w/32.0;
   stroke(128);
   fill(255);
   rect(x,y,32*s,50*s,7*s);
   noStroke();
   fill(c);
   rect(x+2.5*s,y+2.5*s,32*s-5*s,50*s-5*s,4*s);
   
   pushMatrix();
   fill(255);
   translate(x+16*s,y+25*s);
   rotate(radians(45));
   ellipse(0,0,20*s,30*s);
   popMatrix();
   
  textSize(9*s);
   textAlign(CENTER,CENTER);
   text(""+n,x+7*s,y+6*s);
   
   textSize(20*s);
   fill(c);
   text(""+n,x+16*s,y+22*s);
 }

沒有留言:

張貼留言