1.目前時間
void setup()
{
size(600,600);
fill(255,0,0);
textSize(80);
}
void draw()
{
background(255);
text(hour()+":"+minute()+":"+second(),50,100);
text("mills()"+millis()/1000,50,200);
}
2.顯示文字
3.不同字體
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);
}
4.其他的時間計算
PFont font1;
void setup()
{
size(800,600);
fill(255);
textSize(80);
font1 = createFont("微軟正黑體",100);
textFont(font1);
}
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);
}
5.迴圈圖片
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);
}
}
沒有留言:
張貼留言