step01-1 畫撲克牌
step01-2 用函式畫撲克牌
void setup(){
size(500,500);
}
int W=25;
void draw(){
drawCard(100,100);
drawCard(110,110);
drawCard(120,120);
}
void drawCard(int x,int y){
fill(255);
rect(x-W/2,y-W/2,150+W,250+W,20);
fill(#9B3838);
rect(x,y,150,250,20);
}
step02-1 加入文字
void setup(){
size(500,500);
}
int W=25;
void draw(){
drawPokerCard(100,100,"S4");
drawPokerCard(140,140,"H3");
drawPokerCard(180,180,"D5");
drawPokerCard(220,220,"CJ");
}
void drawPokerCard(int x,int y,String face){
fill(255);
rect(x-W/2,y-W/2,150+W,250+W,20);
fill(#9B3838);
rect(x,y,150,250,20);
fill(0);
textSize(40);
text(face,x,y+40);
}
step02-2 加入中文字
void setup(){
size(500,500);
PFont font = createFont("標楷體",40);
textFont(font);
}
int W=25;
void draw(){
drawPokerCard(100,100,"黑桃4");
drawPokerCard(140,140,"紅心3");
drawPokerCard(180,180,"方塊5");
drawPokerCard(220,220,"梅花J");
}
void drawPokerCard(int x,int y,String face){
fill(255);
rect(x-W/2,y-W/2,150+W,250+W,20);
fill(#9B3838);
rect(x,y,150,250,20);
fill(0);
textSize(40);
text(face,x,y+40);
}
step02-3更改文字顏色
void setup(){
size(500,500);
PFont font = createFont("標楷體",40);
textFont(font);
}
int W=25;
void draw(){
drawPokerCard(100,100,"黑桃4");
drawPokerCard(140,140,"紅心3");
drawPokerCard(180,180,"方塊5");
drawPokerCard(220,220,"梅花J");
}
void drawPokerCard(int x,int y,String face){
fill(255);
rect(x-W/2,y-W/2,150+W,250+W,20);
fill(#9B3838);
rect(x,y,150,250,20);
///fill(0);
if(face.indexOf("黑桃")==-1 && face.indexOf("梅花")== -1)fill(#FF0000);
else fill(0);
textSize(40);
text(face,x,y+40);
}
step03-1 隨機
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(140,140,face2);
drawPokerCard(180,180,face3);
drawPokerCard(220,220,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(#9B3838);
rect(x,y,150,250,20);
///fill(0);
if(face.indexOf("黑桃")==-1 && face.indexOf("梅花")== -1)fill(#FF0000);
else fill(0);
textSize(40);
text(face,x,y+40);
}






沒有留言:
張貼留言