2021年11月15日 星期一

嗨壓阿 week06

 week06

1.文字

size(600,600);
fill(255,0,0);
textSize(80);
text("Hello", 50,50); 

2.可互動文字

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

3.計算過了幾個Frame

void setup()
{
  size(600,600);
  fill(255,0,0);
  textSize(80);
}
void draw()
{
  background(255);
  text("Time:"+frameCount, 50,100);
}

4.計算過了幾秒

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);
}

5.時分秒

void setup(){
  size(500,500);
  fill(255,0,0);
  textSize(80);
}
void draw(){
  background(255);
  text(hour()+":"+minute()+":"+second(),50,100);
  text("Mills:"+millis()/1000,50,200);
}

6.印出系統目前所有字型


println(PFont.list());

7.更改字型,印出中文

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

8.滑鼠點擊切換字型

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);
}

9.時分秒

void setup(){
  size(500,500);
  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);
}

10.倒計時

void setup(){
  size(500,500);
  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);
}

11.加中文

PFont font1;
void setup(){
  size(800,500);
  fill(255);//填充顏色
  textSize(80);//文字大小
}
void draw(){
  background(#075BB2);
  String hh=nf(hour(),2);
  String mm=nf(minute(),2);
  String ss=nf(second(),2);
  font1=createFont("標楷體",100);
  textFont(font1);
  text("現在:"+hh+":"+mm+":"+ss,50,100);
  text("上課:15:50:00",50,200);
  
  int now=hour()*60*60+minute()*60+second();
  int next=15*60*60+50*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);
}

12.圖片秀字

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=(i/5)*225;
    image(img[i],x,y);
  }
}






沒有留言:

張貼留言