顯示具有 Week06 標籤的文章。 顯示所有文章
顯示具有 Week06 標籤的文章。 顯示所有文章

2021年11月17日 星期三

Week06

 1 直接用text()寫出Hello


2 改成text()套在draw()中寫出Hello
3 利用frameCount以60fps刷新計時

4 frameCount/60以符合用秒作為計時單位

  另用millis()作為對照,frameCount執行時較慢不準確


5 加入hour() minute() second()用於計時

6 以pFont的pFont.list()查詢現有字體,再以createFont()選擇字型

    textFont()使用文字字型


7 物件font1 font2各用一種字型 按下畫面可改字型
8 字串hh mm ss分別使用hour() minute() second()
9 將現在時間轉為以秒為單位並與下課時間相減 得出剩下時間
10 將剩下時間秒為單位改為時分秒為單位
11 將數字png檔案以陣列讀入並顯示
12 將剩下秒數以數字圖案呈現並調整位置

























2021年11月15日 星期一

鴨力山大week06

size(600,600);//視窗大小
fill(255,0,0);
textSize(80);//字體大小
text("Hello",50,50);


我們可以試著移動字,讓字可以完整被看到
void setup(){
  size(600,600);//視窗大小
  fill(255,0,0);
  textSize(80);//字體大小
}
void draw(){
  text("Hello",50,100);
}


做計時器
void setup(){
  size(600,600);//視窗大小
  fill(255,0,0);
  textSize(80);//字體大小
}
void draw(){
  background(255);
  text("Time:"+frameCount,50,100);
}//每秒60frame,過了幾個frame


void setup(){
  size(600,600);//視窗大小
  fill(255,0,0);
  textSize(80);//字體大小
}
void draw(){
  background(255);
  text("Time:"+frameCount/60,50,100);
  text("millis()"+millis(),50,200);
}//每秒60frame,過了幾個frame
//kilo-meter centi-milli-millis千分之一秒
//km   m     cm    mm
//kg   g           mg


void setup(){
  size(600,600);//視窗大小
  fill(255,0,0);
  textSize(80);//字體大小
}
void draw(){
  background(255);
  text(hour()+":"+minute()+":"+second(),50,100);
  text("millis()"+millis()/1000,50,200);
}//每秒60frame,過了幾個frame
//kilo-meter centi-milli-millis千分之一秒
//km   m     cm    mm
//kg   g           mg


使用println(PFont.list());列出電腦內的字體


顯示中文
PFont myFont;
void setup(){
  size(500,500);
  myFont=createFont("標楷體",100);
  textFont(myFont);
  text("中文",100,100);
}


按著滑鼠可以換字體
PFont font1,font2;
void setup(){
  size(500,500);
  font1 = createFont("標楷體",100);
  textFont(font1);
  font2 = createFont("微軟正黑體 Bold",100);
}
void draw(){
  background(0);
  text("中文",100,100);
  if(mousePressed) textFont(font2);
  else textFont(font1);
}


void setup(){
  size(600,600);
  fill(255,0,0);
  textSize(80);
}
void draw(){
  background(255);
  String hh=nf(hour(),2);
  String mm=nf(minute(),2);
  String ss=nf(second(),2);
  text(hh+":"+mm+":"+ss,50,100);
}




倒數計時
void setup(){
  size(600,600);
  fill(255);//白色的字
  textSize(80);
}
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("下課:15:40:00",50,200);
  
  int now = hour()*60*60 + minute()*60 + second();
  int next =15    *60*60 + 40      *60 + 0;
  int remain = next-now;
  text("剩下:"+remain,50,300);
}



倒數計時會轉換成時分秒
void setup(){
  size(600,600);
  fill(255);//白色的字
  textSize(80);
}
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("下課:15:40:00",50,200);
  
  int now = hour()*60*60 + minute()*60 + second();
  int next =15    *60*60 + 40      *60 + 0;
  int remain = next-now;
  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);
}




顯示圖片
PImage [] img =new PImage[10];
void setup(){
  size (1120,450);
  for(int i=0; i<10;i++) img[i]=loadImage(i+".png");
}
void draw(){
  for(int i=0;i<10;i++){
    int x =(i%5)*224,y=int(i/5)*225;
    image(img[i],x,y);
  }
}


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("下課:15:40:00",50,200);
  
  int now = hour()*60*60 + minute()*60 + second();//總秒數
  int next = 16   *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=800;
  while(remain>0){
    int n = remain%10;
    remain = remain / 10;
    image( img[n], x,100,100,100);
    x-=100;
  }
}



 

week06

 一.

1.程式碼:
size(600,600);
fill(255,0,0);
textSize(40);///文字大小

text("Hello",50,50);///文字內容與位置


2.程式碼:

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


位置根據左下角的點

3.程式碼:

void setup(){
  size(600,600);
  fill(255,0,0);
  textSize(80);
}
void draw(){
  background(255);///背景白色
   text("Time:"+frameCount,50,100);///每秒60frame
}

程式碼:
void setup(){
  size(600,600);
  fill(255,0,0);
  textSize(80);
}
void draw(){
  background(255);
   text("Time:"+frameCount/60,50,100);
   text("millis():"+millis()/1000,50,200);///millis千分之一秒比較準確
}


4.程式碼:
void setup(){
  size(600,600);
  fill(255,0,0);
  textSize(80);
}
void draw(){
  background(255);
   text(hour()+":"+minute()+":"+second(),50,100);///電腦裡目前顯示的時間
   text("millis():"+millis()/1000,50,200);
}



二.
1.程式碼:
PFont myFont;///宣稱字體
void setup(){
   size(500,500);
   myFont=createFont("標楷體",100);
   textFont(myFont);
   text("中文",100,100);
}

讓中文能顯示出來

2.程式碼:
PFont font1,font2;
void setup(){
   size(500,500);
   font1=createFont("標楷體",100);
   textFont(font1);
   font2=createFont("微軟正黑體",100);
}
void draw(){
   background(0);
   text("中文",100,100);
   if(mousePressed)textFont(font2);
   else textFont(font1);
}

切換字體

三.
1.程式碼:
void setup(){
  size(600,600);
  fill(255,0,0);
  textSize(80);
}
void draw(){
  background(255);
  String hh=nf(hour(),2);
  String mm=nf(minute(),2);
  String ss=nf(second(),2);
  text(hh+":"+mm+":"+ss,50,100);
}

顯示當前時間

2.程式碼:
void setup(){
  size(600,600);
  fill(255);
  textSize(80);
}
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("下課:15:40:00",50,200);
  
  int now=hour()*60*60+minute()*60+second();///現在時間的總秒數
  int next=15*60*60+40*60+0;///下課時間的總秒數
  int remain=next-now;///剩下的秒數
  text("剩下:"+remain,50,300);
}

現在時間
下課時間
剩餘時間

程式碼:
void setup(){
  size(600,600);
  fill(255);
  textSize(80);
}
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("下課:15:40:00",50,200);
  
  int now=hour()*60*60+minute()*60+second();
  int next=15*60*60+40*60+0;
  int remain=next-now;
  text("剩下:"+remain,50,300);
  hh=nf(remain/60/60,2);
  mm=nf(remain/60%60,2);
  ss=nf(remain%60,2);
  text("剩下:"+hh+":"+mm+":"+ss,50,400);
}
現在時間
下課時間
剩餘時間(秒)
剩餘時間(換算分時秒)

四.
1.程式碼:
PImage [] img=new PImage[10];
void setup(){
   size(1120,450);
   for(int i=0;i<10;i++)img[i]=loadImage(i+".png");
}
void draw(){
   for(int i=0;i<10;i++){
      int x=(i%5)*224,y=int(i/5)*225;///x,y為圖片的位置
      image(img[i],x,y);///img[i]為圖片的名稱(0~9)
   }
}

把圖片印出來
2.程式碼:
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("下課:15:40:00",50,200);
  
  int now=hour()*60*60+minute()*60+second();
  int next=15*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=800;
  while(remain>0){
    int n = remain%10;
    remain = remain / 10;
    image( img[n], x,100,100,100);
    x-=100;
  }
}



























week06(文字)

 秀出文字


秀出時間變數(frame)


秀出時間(計時秒)

millis是千分之秒,較準

秀出時間(電腦時間)


載入中文字體


中文字體小變化

按下滑鼠就改變字體

利用字串調整格式秀時間(nf)

nf可自動將數字前方補0

建立倒數計時

使用圖片來取代文字

//需先將圖片更改名字,並放置目錄之下
//Q: 能不能改用漂亮的圖片, 來顯示數字
//(1) 在 images.google.com 找到10張圖 0...9
//    ex. IconsPng Golden Number 1 Icons PNG
//(2) 存在我們的專案目錄,檔名: 0.png ~ 9.png
//   使用陣列讀進來
PImage [] img = new PImage[10];//0...9
PFont font;
void setup(){
  //size(224*5,225*2);
  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("下課:15:40:00", 50,200);
  
  int now = hour()*60*60 + minute()*60 + second();//總秒數
  int next = 16   *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=800;
  while(remain>0){
    int n = remain%10;
    remain = remain / 10;
    image( img[n], x,100,100,100);
    x-=100;
  }
}

岩壁悲歌 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;

  }

}