文字 & 字型 & 字串
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("Hello:"+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);
}
5.現在時間幾時幾分幾秒
程式如下:
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);
}
9.用字串顯示現在時間
程式如下:
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);
}
10.倒數時間
程式如下:
void setup(){
size(600,600);
fill(255,0,0);
textSize(80);
}
void draw(){
background(#084BB2);
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.倒數時間有時分秒的版本
程式如下:
void setup(){
size(800,600);
fill(255,0,0);
textSize(80);
}
void draw(){
background(#084BB2);
String hh=nf(hour(),2);
String mm=nf(minute(),2);
String ss=nf(second(),2);
text("現在:"+hh+":"+mm+":"+ss,50,100);
text("下課:16:40:00",50,200);
int now=hour()*60*60+minute()*60+second();
int next=16*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);
}
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=int(i/5)*225;
image(img[i],x,y);
}
}
13.改變位置
程式如下:
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*100,y=0;
image(img[i],x,y,100,100);
}
}
14.用圖片倒數 結合之前的程式
程式如下:
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;
}
}















沒有留言:
張貼留言