2022/09/12 Week02
1. 畫一張有弧度的卡片
size(500,500);
rect(90,90, 170, 270, 20);
fill(#E3BB1B); ///橘色
rect(100,100, 150, 250, 20);
///在位置100,100的地方,畫一個寬270、長170、弧度20的方形
2. 畫很多張卡片---加上function(drawCard)
void setup(){
size(500,500);
}
int W=20;
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(#E3BB1B);
rect(x, y, 150, 250, 20);
}
3. 畫一些Poker牌
void setup(){
size(500,500);
}
int W=20;
void draw(){
drawPokerCard(100,100, "S1"); /// Spade黑桃
drawPokerCard(130,150, "H1"); /// Heart紅心
drawPokerCard(160,200, "D1"); /// Diamand方塊
drawPokerCard(190,250, "C1"); /// Club梅花
} ///變數: int=整數,String=字串
void drawPokerCard(int x, int y, String face){
fill(255);
rect(x-W/2, y-W/2, 150+W, 250+W, 20);
fill(#E3BB1B);
rect(x, y, 150, 250, 20);
fill(0); ///字體黑色
textSize(30); ///字體大小
text(face, x+10,y+35); ///字體印的位置
}
4. 畫一些Poker牌+中文字體
void setup(){
size(500,500);
PFont font = createFont("標楷體", 40);
textFont(font);
}
int W=20;
void draw(){
drawPokerCard(100,100, "黑桃1");
drawPokerCard(130,150, "紅心1");
drawPokerCard(160,200, "方塊1");
drawPokerCard(190,250, "梅花1");
} ///變數: int=整數, String=字串
void drawPokerCard(int x, int y, String face){
fill(255);
rect(x-W/2, y-W/2, 150+W, 250+W, 20);
fill(#E3BB1B);
rect(x, y, 150, 250, 20);
fill(0);
textSize(30);
text(face, x+10,y+35);
}
5. 改Poker牌的字體顏色
void setup(){
size(500,500);
PFont font = createFont("標楷體", 40);
textFont(font);
}
int W=20;
void draw(){
drawPokerCard(100,100, "黑桃1");
drawPokerCard(130,150, "紅心1");
drawPokerCard(160,200, "方塊1");
drawPokerCard(190,250, "梅花1");
}///變數: int=整數 , String=字串
void drawPokerCard(int x, int y, String face){
fill(255);
rect(x-W/2, y-W/2, 150+W, 250+W, 20);
fill(#E3BB1B);
rect(x, y, 150, 250, 20);
///fill(0);
if(face.indexOf("黑桃") == -1 && face.indexOf("梅花") == -1) fill(#FF0000);
else fill(0);
textSize(30);
text(face, x+10,y+35);
}
6. 隨機撲克牌
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);
///random(13)=0~12,因此要+1,int()要取整數
}
int W=20;
String face1, face2, face3, face4;
void draw(){
drawPokerCard(100,100, face1 );
drawPokerCard(130,150, face2 );
drawPokerCard(160,200, face3 );
drawPokerCard(190,250, face4 );
}///變數: int=整數 , String=字串
void drawPokerCard(int x, int y, String face){
fill(255);
rect(x-W/2, y-W/2, 150+W, 250+W, 20);
fill(#E3BB1B);
rect(x, y, 150, 250, 20);
///fill(0);
if(face.indexOf("黑桃") == -1 && face.indexOf("梅花") == -1) fill(#FF0000);
else fill(0);
textSize(30);
text(face, x+10,y+35);
}
7. 按滑鼠左鍵隨機更新撲克牌
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);
///random(13)=0~12,因此要+1,int()要取整數
}
void mousePressed(){
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);
///random(13)=0~12,因此要+1,int()要取整數
}
int W=20;
String face1, face2, face3, face4; ///牌的字
void draw(){
drawPokerCard(100,100, face1 );
drawPokerCard(130,150, face2 );
drawPokerCard(160,200, face3 );
drawPokerCard(190,250, face4 );
}///變數: int=整數 , String=字串
void drawPokerCard(int x, int y, String face){
fill(255);
rect(x-W/2, y-W/2, 150+W, 250+W, 20);
fill(#E3BB1B);
rect(x, y, 150, 250, 20);
///fill(0);
if(face.indexOf("黑桃") == -1 && face.indexOf("梅花") == -1) fill(#FF0000);
else fill(0);
textSize(30);
text(face, x+10,y+35);
}
沒有留言:
張貼留言