2021年11月15日 星期一

week06課程

 時間運作

1.字體呈現與預設位置

void setup(){
    size(500,500);
    fill(255,0,0);
    textSize(40);
    text("Hello",50,50);
}
void draw(){
   text("Hello",50,100);
}

2.顯示影格

void setup(){
    size(500,500);
    fill(255,0,0);
    textSize(40);
}
void draw(){
    background(255);
    text("Time:"+frameCount,50,100);//1秒加60個影格
}
void setup(){
    size(500,500);
    fill(255,0,0);
    textSize(40);
}
void draw(){
    background(255);
    text("Time:"+frameCount/60,50,100);//讓frameCount/60顯示正常速度
}
void setup(){
    size(500,500);
    fill(255,0,0);
    textSize(40);
}
void draw(){
    background(255);
    text("Time:"+frameCount/60,50,100);//讓frameCount/60顯示正常速度
    text("millis():"+millis()/1000,50,200);//millis是1/1000秒,相較於frameCount更為準確
}

3.顯示時間

void setup(){
size(500,500);
fill(255,0,0);
textSize(40);
}
void draw()
{
  background(255);
  text(hour()+":"+minute()+":"+second(),50,100);//用hour,minute,second來呈現現實時間
  text("millis():"+millis()/1000,50,200);//millis是1/1000秒
}

輸入特殊字體

1.字體清單

println(PFont.list());

2.顯示文字

PFont myFont;//宣告變數
void setup(){
  size(500,500);
  myFont = createFont("標楷體",100);//設定字體和大小
  textFont(myFont);
  text("中文",100,100);//顯示文字大小
}

3.切換字型

PFont font1,font2;//宣告變數
void setup(){
  size(500,500);
  font1 = createFont("標楷體",100);//設定字體和大小
  textFont(font1);
  font2 = createFont("微軟中黑體",100);//設定字體和大小
  textFont(font2);
}
void draw(){
  background(0);
  text("中文",100,100);
  if(mousePressed)textFont(font2);
  else textFont(font1);
}


顯示幾位數

1.nf(number formate)

void setup(){
size(500,500);
fill(255,0,0);
textSize(40);
}
void draw()
{
  background(255);
  String hh=nf(hour(),2);//nf後設定的數字可以顯示幾位數
  String mm=nf(minute(),2);
  String ss=nf(second(),2);
  text(hh+":"+mm+":"+ss+"",50,100);
  text("millis():"+millis()/1000,50,200);//millis是1/1000秒
}

2.顯示倒數和剩下時間

PFont myFont;//宣告變數
void setup(){
size(500,500);
myFont = createFont("標楷體",100);//設定字體和大小
textFont(myFont);
fill(255,0,0);
textSize(60);
}
void draw()
{
  background(255);
  String hh=nf(hour(),2);//nf後設定的數字可以顯示幾位數
  String mm=nf(minute(),2);
  String ss=nf(second(),2);
  text("現在:"+hh+":"+mm+":"+ss+"",50,100);
  text("睡覺:02:00:00",50,200);
  int now = hour()*60*60+minute()*60+second();
  int next = 02*60*60+00*60+00;
  int remain = next-now;
  text("剩下:"+remain+"秒",50,300);
  hh=nf(remain/60*60%60,2);//讓remain得出的結果轉換成小時分鐘秒數
  mm=nf(remain/60%60,2);
  ss=nf(remain%60,2);
  text("剩下:"+hh+":"+mm+":"+ss,50,400);
}










沒有留言:

張貼留言