นาฬิกาดิจิตอล
//digital clock
int cx=250;//centerX
int cy=150;//centerY
void setup() {
size(500, 500);
}
void draw() {
background(#A2FAF9);//light blue
time();
date();
}
//time function
void time() {
fill(0);
textSize(50);
//hour
if (hour()<10) {
text("0"+hour(), cx-150, cy-100);
} else {
text(hour(), cx-150, cy-100);
}
//minute
if (minute()<10) {
text(":"+"0"+minute(), cx-50, cy);
} else {
text(":"+minute(), cx-50, cy);
}
//second
if (second()<10) {
text(":"+"0"+second(), cx+50, cy);
} else {
text(":"+second(), cx+50, cy);
}
//Hr Min Sec's text
textSize(15);
text("Hr", cx-140, cy-50);
text("Min", cx-40, cy-50);
text("Sec", cx+60, cy-50);
}
//Date's function
void date() {
textSize(40);
//day
text(day(), cx-150, cy+200);
//month
text(month(), cx-50, cy+200);
//year
text(year(), cx+50, cy+200);
//date 's text
textSize(15);
text("Day", cx-140, cy+150);
text("Month", cx-40, cy+150);
text("Year", cx+60, cy+150);
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น