2021年11月15日 星期一

岩壁悲歌 Week06

 2021/11/15 文字與時間的運用

------------------------------------------------------------

一開始沒給顏色的話,預設都是白色

加入void setup&void draw達到互動的效果

frameCount=>影格數,void draw()函式是每秒60個影格

millis()/1000會比frameCount/60還來的準確

hour()=>小時

minute()=>分鐘

second()=>秒

中文顯示不出來

P語言裡面的字體

PFont函式

原本是標楷體,按一下之後變成微軟正黑體

利用字串"String"來顯示現在時間

nf=>number font

現在時間與下課時間還有相差秒數,只是中文還沒出來

-------------------------------------------------------------------------------------

宣告圖片陣列,讀取陣列圖片,接著印出來

接著將數字替換成圖片

PImage [] img = new PImage[10];

PFont font;

void setup(){

  size(  1120, 450  );

  for(int i=0; i<10; i++) img[i]=loadImage(i+".png");

  fill(255);

  font = createFont("標楷體",80);

  textFont(font);

}

void draw(){

  background(#075BB2);

  String hh=nf(hour(),2);

  String mm=nf(minute(),2);

  String ss=nf(second(),2);

  text("現在:"+hh+":"+mm+":"+ss, 50,100);

  text("下課:17:40:00", 50,200);

  

  int now = hour()*60*60 + minute()*60 + second();

  int next = 17   *60*60 + 40      *60 + 0;

  int remain = next-now;

  if(remain<0) remain += 24*60*60;

  text("剩下:"+remain, 50,300);

  hh = nf(remain/60/60%60, 2);

  mm = nf(remain/60%60, 2);

  ss = nf(remain%60, 2);

  text("剩下:"+hh+":"+mm+":"+ss, 50,400);

  int x=900;

  while(remain>0){

    int n = remain%10;

    remain = remain / 10;

    image( img[n], x,100,100,100);

    x-=100;

  }

}

沒有留言:

張貼留言