嗨
🔸今天第一個就教hello
size(600,600);
fill(255,0,0);
textSize(80);//放大字
text("Hello",50,50);//一開始字的fill
🔹把hello往下移動
size(600,600);
fill(255,0,0);
textSize(80);
text("Hello",50,100);
🔸也可以寫成這樣子,是一樣的意思
void setup()
{
size(600,600);
fill(255,0,0);
textSize(80);
}
void draw(){
text("Hello",50,100);
}
🔹接著再修改一下程式碼,frame加上去,背景更改為白色
void setup()
{
size(600,600);
fill(255,0,0);
textSize(80);
}
void draw(){
background(255);//白色
text("Time:"+frameCount,50,100);
}//每秒60個frame,過了幾個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);
}//每秒60個frame,過了幾個frame
🔹接著我們讓他/1000,下面的millis更精準
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);
}//每秒60個frame,過了幾個frame
🔸再改一下程式碼,加入"hour()+":"+minute()+":"+second()"
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);
}//每秒60個frame,過了幾個frame
🔹我們試著打入中文,發現失敗了
void setup()
{
size(600,600);
fill(255,0,0);
textSize(80);
}
void draw(){
background(255);//白色
text(hour()+":"+minute()+":"+second(),50,100);
text("中文:"+millis()/1000,50,200);//準
//text("millis():"+millis()/1000,50,200);
}//每秒60個frame,過了幾個frame
🔸新開一個視窗,打上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("微軟正黑體",100);
}
void draw()
{
background(0);
text("中文",100,100);
if(mousePressed)textFont(font2);
else textFont(font1);
}
🔹加入字串String就可以直接印出時間了
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);
//text(hour()+":"+minute()+":"+second(),50,100);
}
🔸倒數下課時間
void setup()
{
size(600,600);
fill(255);
textSize(80);
}
void draw()
{
background(#005BB2);
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(#005BB2);
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);
}
🔸用for迴圈讀進十張圖並顯示出來
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];//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;
}
}
沒有留言:
張貼留言