week04
第一步 畫出格子
void setup(){
size(800,800);
}
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);
}
}
}
第二步 幫卡牌上色
void setup(){
size(800,800);
}
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(800,800);
}
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);///gray stroke
fill(255);///white
rect(x, y, 32, 50, 7);///7就是變成圓圓的
noStroke();
fill(c);
rect(x+2, y+2, 32-5, 50-5, 4);
}
第四步 加UNO中間白白的橢圓形
void setup(){
size(800,800);
}
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);///gray stroke
fill(255);///white
rect(x, y, 32, 50, 7);
noStroke();
fill(c);
rect(x+2, y+2, 32-5, 50-5, 4);
pushMatrix();
fill(255);
translate(x+16, y+25);
rotate(radians(45));
ellipse(0, 0, 20, 30);
popMatrix();
}
第五步 加UNO的數字
......
pushMatrix();
fill(255);
translate(x+16, y+25);
rotate(radians(45));
ellipse(0, 0, 20, 30);
popMatrix();
textAlign(CENTER, CENTER);
textSize(9);///左上的
text("1", x+7, y+6);
textSize(20);///中間的
fill(c);
text("1", x+16, y+22);
}
第六步 將UNO的數字從1排到10
.........
void drawCard(int x, int y, color c, int n){
stroke(128);///gray stroke
fill(255);///white
rect(x, y, 32, 50, 7);
noStroke();
fill(c);
rect(x+2, y+2, 32-5, 50-5, 4);
pushMatrix();
fill(255);
translate(x+16, y+25);
rotate(radians(45));
ellipse(0, 0, 20, 30);
popMatrix();
textAlign(CENTER, CENTER);
textSize(9);
text(" "+n, x+7, y+6);
textSize(20);
fill(c);
text(" "+n, x+16, y+22);
}
第七步 將UNO的數字隨機打亂
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 [][]card = new int[8][11];
int [] cardN = new int[88];//card number
int [] cardC = new int[88];//card color
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);
drawCard(j*32, i*50, cardC[i*11+j], cardN[i*11+j]);
}
}
}
.........
}
第八步 將UNO放大
..........
//int [][]card = new int[8][11];
int [] cardN = new int[88];//card number
int [] cardC = new int[88];//card color
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);
drawCard(j*32, i*50, cardC[i*11+j], cardN[i*11+j], 32);
}
}
drawCard(500, 100, cardC[7], cardN[77], 128);
}
void drawCard(int x, int y, color c, int n, int w){
float s = w/32.0;///scale size
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();
textAlign(CENTER, CENTER);
textSize(9*s);
text(" "+n, x+7*s, y+6*s);
textSize(20*s);
fill(c);
text(" "+n, x+16*s, y+22*s);
}
第九步 作弊方法
.........
void draw(){
background(255);
if(mousePressed && mouseButton == RIGHT){///cheat key, peak all
for(int i=0; i<8; i++){
for(int j=0; j<11; j++){
///drawCard(j*32, i*50, c[i%4], j);
drawCard(j*32, i*50, cardC[i*11+j], cardN[i*11+j], 32);
}
}
}else drawCard(50, 50, #000000, 99, 128);///get card here
for(int i=0; i<myCard; i++){
drawCard(450+40*i, 50, cardC[i], cardN[i], 128);
}
}
int myCard = 0;
void mousePressed(){
if(mouseButton == LEFT) myCard++;
}
........











沒有留言:
張貼留言