2022年9月12日 星期一

互動技術week02

面(紙牌)

rect( x , y , w , h , arc );


呼叫函式

void draw()
{
  drawcard(100,100);
  drawcard(200,200);
}
void drawcard(int x,int y)
{
  fill(255);
  rect(x-w/2,y-w/2,150+w,250+w,20);
  fill(#00FF0A);
  rect(x,y,150,250,20);
}

字串、顯示字串

String face = "Hi"
textSize(30);
text(face,x,y+30);

設定字型

PFont font = createFont(字體名稱,字體大小);
textFont(font);


字串內容條件

if(face.indexOf(條件) == -1 && face.indexOf(條件) == -1)fill(#FF0000);
else fill(0);

撲克牌洗牌

void setup()
{
  size(500,500);
  PFont font = createFont("標楷體",30);
  textFont(font);
  String [] flower = {"黑桃","紅心","方塊","梅花"};
  String [] number = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
  face1 = flower[int(random(4))]+number[int(random(13))];
  face2 = flower[int(random(4))]+number[int(random(13))];
  face3 = flower[int(random(4))]+number[int(random(13))];
  face4 = flower[int(random(4))]+number[int(random(13))];
}
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);
}
void drawPokercard(int x,int y ,String face)
{
  fill(255);
  rect(x-w/2,y-w/2,150+w,230+w,20);
  fill(#E3FCD6);
  rect(x,y,150,230,20);
  if(face.indexOf("黑桃") == -1 && face.indexOf("梅花") == -1)fill(#FF0000);
  else fill(0);
  textSize(30);
  text(face,x,y+30);
}


沒有留言:

張貼留言