2022年9月12日 星期一

鯉魚week02

 1.畫卡片(有弧度)
    size(500,500);  //視窗大小
    fill(#F5DAA8);  //顏色
    rect(100,100,150,250,20);  //弧度


2.卡片(有邊框)
    size(500,500);  //視窗大小
    int w=20;
    rect(100-w/2,100-w/2,150+w,250+w,20);  //弧度
    fill(#F5DAA8);  //顏色
    rect(100,100,150,250,20);  //弧度

3.畫多張卡片
void setup(){
   size(500,500); 
}
int w=25;
void draw(){
  drawCard(100,100);  //使用函式
  drawCard(130,130);  //使用函式
  drawCard(160,160);  //使用函式  
}
void drawCard(int x,int y){
  fill(255);
  rect(x-w/2,y-w/2,150+w,250+w,20);  //弧度
  fill(#F5DAA8);
  rect(x,y,150,250,20);  //弧度
}

4.撲克牌
void setup(){
   size(500,500); 
}
int w=25;
void draw(){ 
  drawPokerCard(100,100,"S4");   //使用函式
  drawPokerCard(130,150,"H3");  //使用函式
  drawPokerCard(160,200,"D5");  //使用函式  
  drawPokerCard(190,250,"CJ");   //使用函式  
}
void drawPokerCard(int x,int y,String face){  //牌面
  fill(255);
  rect(x-w/2,y-w/2,150+w,250+w,20);  //弧度
  fill(#F5DAA8);
  rect(x,y,150,250,20);  //弧度
  
  fill(0);  //字體顏色
  textSize(40);  //字體大小
  text(face,x,y+40);  
}
5.查找字型相關文件

6.顯示中文字
void setup(){
   size(500,500); 
   PFont font = createFont("標楷體",40);
   textFont(font);
}
int w=25;
void draw(){
  drawPokerCard(100,100,"黑桃4");  //使用函式
  drawPokerCard(130,150,"紅心3");  //使用函式
  drawPokerCard(160,200,"方塊5");  //使用函式  
  drawPokerCard(190,250,"梅花J");  //使用函式  
}
void drawPokerCard(int x,int y,String face){  //牌面
  fill(255);
  rect(x-w/2,y-w/2,150+w,250+w,20);  //弧度
  fill(#F5DAA8);
  rect(x,y,150,250,20);  //弧度
  
  fill(0);  //字體顏色
  textSize(40);  //字體大小
  text(face,x,y+40);  
}
7.字體顏色不同
void setup(){
   size(500,500); 
   PFont font = createFont("標楷體",40);
   textFont(font);
}
int w=25;
void draw(){
  drawPokerCard(100,100,"黑桃4");  //使用函式
  drawPokerCard(130,150,"紅心3");  //使用函式
  drawPokerCard(160,200,"方塊5");  //使用函式  
  drawPokerCard(190,250,"梅花J");  //使用函式  
}
void drawPokerCard(int x,int y,String face){  //牌面
  fill(255);
  rect(x-w/2,y-w/2,150+w,250+w,20);  //弧度
  fill(#F5DAA8);
  rect(x,y,150,250,20);  //弧度
  
  if(face.indexOf("黑桃") == -1 && face.indexOf("梅花") == -1)  fill(#FF0000);
  else fill(0);  //字體顏色
  textSize(40);  //字體大小
  text(face,x,y+40);  
}
8.隨機牌面(洗牌shuffle)
void setup(){
   size(500,500); 
   PFont font = createFont("標楷體",40);
   textFont(font);
   String [] flower = {"黑桃","紅心","方塊","梅花"};  //陣列
   face1 = flower[int(random(4))]  + int(random(13)+1);  //取整數
   face2 = flower[int(random(4))]  + int(random(13)+1);  
   face3 = flower[int(random(4))]  + int(random(13)+1);  
   face4 = flower[int(random(4))]  + int(random(13)+1);  
}
String face1,face2,face3,face4;
void draw(){
  drawPokerCard(100,100, face1);  //使用函式
  drawPokerCard(130,150, face2);  //使用函式
  drawPokerCard(160,200, face3);  //使用函式  
  drawPokerCard(190,250, face4);  //使用函式  
}
void drawPokerCard(int x,int y,String face){  //牌面
  int w=25;
  fill(255);
  rect(x-w/2,y-w/2,150+w,250+w,20);  //弧度
  fill(#F5DAA8);
  rect(x,y,150,250,20);  //弧度
  
  if(face.indexOf("黑桃") == -1 && face.indexOf("梅花") == -1) fill(#FF0000);
  else fill(0);  //字體顏色
  textSize(40);  //字體大小
  text(face,x,y+40);  
}

沒有留言:

張貼留言