void setup() {
size(200, 200);
colorMode(HSB, 360, 100, 100, 100);
background(0, 0, 0);
smooth();
frameRate(15);
}
void draw() {
//①背景を黒色に塗りつぶし、座標を画面の中央へ移動する。
background(0, 0, 0);
translate(width / 2, height / 2);
//②時計の白い裏板を描く。
noStroke();
fill(0, 0, 100);
ellipse(0, 0, 170, 170);
//③時刻を表す黒丸をそれぞれ描く。
fill(0, 0, 0);
for(int i = 0; i < 12; i++) {
pushMatrix();
rotate(radians(i * 30));
ellipse(0, -75, 10, 10);
popMatrix();
}
//④日本標準時の時刻をWEB上で取得する。
String jst[] = loadStrings("http://ntp-a1.nict.go.jp/cgi-bin/time");
String[][] time = new String[3][];
time[0] = match(jst[0], "(?<= )..(?=:)");
time[1] = match(jst[0], "(?<=:)..(?=:)");
time[2] = match(jst[0], "(?<=:)..(?= )");
//⑤時計の針を3本描く。
int[][] hand = {{int(time[0][0]) * 30 + int(int(time[1][0]) / 2), 5, -55}, {int(time[1][0]) * 6, 3, -75}, {int(time[2][0]) * 6, 1, -75}};
stroke(0, 0, 0);
fill(0, 0, 100);
for(int i = 0; i < 3; i++) {
pushMatrix();
rotate(radians(hand[i][0]));
strokeWeight(hand[i][1]);
line(0, 0, 0, hand[i][2]);
popMatrix();
}
//⑥時計の針の留めピンを描く。
fill(0, 0, 0);
ellipse(0, 0, 7, 7);
}