int MARGIN = 20;
Clock myClock = new Clock();
int time1 = 0;
int time2 = 0;
void setup() {
size(700,500);
smooth();
frameRate(30);
}
void draw() {
stroke(255);
background(0);
myClock.getTime();
myClock.draw();
}
class Clock {
float s, m, h;
Clock(){
}
void getTime(){
s = second();
m = minute() + (s/60.0);
h = hour()%12 + (m/60.0);
}
void draw(){
//右側の描画
fill(255);
rect(450,200,120,40);
fill(0);
stroke(0);
ellipse(510,212,2,2);
ellipse(510,230,2,2);
fill(255);
stroke(255);
int a=470;
int b=185;
rect(465,175,20,15);
rect(465+60,175,20,15);
rect(465,175+75,20,15);
rect(465+60,175+75,20,15);
stroke(0);
fill(0);
triangle(a,b,a+8,b,a+4,b-5);
triangle(a,b+70,a+8,b+70,a+4,b+70+5);
triangle(a+60,b,a+8+60,b,a+4+60,b-5);
triangle(a+60,b+70,a+8+60,b+70,a+4+60,b+70+5);
textSize(38);
text(nf(time1,2),455,235);
text(nf(time2,2),455+60,235);
int lenge = 200;
//点の描画
translate(lenge, lenge);
rotate(radians(180));
pushMatrix();
fill(128);
noStroke();
for(int i=0; i<60; i++){
rotate(radians(6));
ellipse(lenge-MARGIN,0,3,3);
}
for(int i=0; i<12; i++){
rotate(radians(30));
ellipse(lenge-MARGIN,0,10,10);
}
//針の描画
popMatrix();
noFill();
stroke(255);
pushMatrix();
rotate(radians(s*(360/60)));
strokeWeight(1);
line(0,0,0,lenge-MARGIN);
popMatrix();
pushMatrix();
rotate(radians(m*(360/60)));
strokeWeight(2);
line(0,0,0,lenge-MARGIN);
popMatrix();
pushMatrix();
rotate(radians(h*(360/12)));
strokeWeight(4);
line(0,0,0,(lenge*3)/4-MARGIN);
popMatrix();
}
}
void mousePressed(){
if(mouseX>465 & mouseX<485){
if(mouseY>175 & mouseY<190){
if(time1<24){
time1++;
}
}else if(mouseY>250 & mouseY<265){
if(time1>0){
time1--;
}
}
}
if(mouseX>465+60 & mouseX<485+60){
if(mouseY>175 & mouseY<190){
if(time2<59){
time2++;
}
}else if(mouseY>250 & mouseY<265){
if(time2>0){
time2--;
}
}
}
}
直接あって話とか、メールとか、合宿前までに設定するの面倒だと思うので。