20. นาฬิกา
คำสั่ง
int s = second() อ่านค่าวินาทีจากเครื่องคอมพิวเตอร์
int m = minute() อ่านค่านาทีจากเครื่องคอมพิวเตอร์
int h = hour() อ่านค่าชั่วโมงจากเครื่องคอมพิวเตอร์
nf(h,2) แปลงจากเลขจำนวนเต็ม เป็นตัวอักษร 2 หลัก
String กำหนดตัวแปรเป็น String
----------------------------------------------------------------------------------------
PFont myFont;
void setup() {
size(550,300);
background(0);
myFont = createFont("Courier New", 32);
textFont(myFont);
}
void draw() {
background(0);
int s = second(); // Values from 0 - 59
int m = minute(); // Values from 0 - 59
int h = hour(); // Values from 0 - 23
String clock = nf(h,2)+':'+nf(m,2)+':'+nf(s,2);
textSize(100);
text(clock, 40, 150);
}