Digital Clock

Screen Shot 2015-02-15 at 1.03.40 AM
Objective
To program a digital clock in processing.
Project done in a week, first experience in programming and processing.
This clock shows 4 different time tones in one screen, will zone in when mouseover.

[fvplayer src=”http://www.wangvivian.com/wp-content/uploads/2015/02/clock1.mp4″ width=”1462″ height=”1080″ autoplay=”true” loop=”true” splash=”http://www.wangvivian.com/wp-content/uploads/2015/02/Screen-Shot-2015-02-15-at-12.34.11-AM.png”]

 Source Code
//variables
 int x=400;
 int y=300;
 // 4 variables, 1 for each square's brightness
float b0 = 0;
float b1 = 126;
float b2 = 255;
 
 
DigitalClock digitalClock,digitalClock1,digitalClock2, digitalClock3;
//DigitalClock1 digitalClock4, digitalClock5,digitalClock6, digitalClock7;

void setup() { 
 size(800, 600);
 noStroke ();
 
}
void draw() { 
 digitalClock = new DigitalClock(40, width/2, height/2+15, x-380, y-270,x-380, y-230, x-380, y-190);
 digitalClock1 = new DigitalClock(40, width/2, height/2+15, x+380, y-270,x+380, y-230, x+380, y-190);
 digitalClock2 = new DigitalClock(40, width/2, height/2+15, x+380, y+190,x+380, y+230, x+380, y+270);
 digitalClock3 = new DigitalClock(40, width/2, height/2+15, x-380, y+190,x-380, y+230, x-380, y+270); 
 
 

 background(255); 
 // Draw lines 
 line(width/2, 0, width/2, height); 
 line(0, height/2, width, height/2); 
 // Fade rects 
 b0 = b0 - 1; 
 b1 = b1 - 1; 
 b2 = b2 - 1; 
 
 // Fill and draw each rect 
 //clock
 fill(b0,b1,b2); 
 //fill(0,126,255);
 rect(0, 0, x, y); 
 digitalClock.getTime();
 digitalClock.display();
 //clock1
 //fill(b3,b4,b5); 
 fill(250,225,58);
 rect(x, 0, 800-x, y); 
 digitalClock1.getTime();
 digitalClock1.display1();
 //clock2
 //fill(b6,b7,b8); 
 fill (246,38,136);
 rect(x, y, 800-x, 600-y); 
 digitalClock2.getTime();
 digitalClock2.display2(); 
 //clock3
 //fill(b9,b10,b11); 
 fill(174,227,33); 
 rect(0, y, x, 600-y); 
 digitalClock3.getTime();
 digitalClock3.display3();
 
 

 
 // Mouse location sets full brightness 
 
 
 if (mouseX < x && mouseY < y) { filter(INVERT);
 b0 = 255; 
 
 if(x<=600) x+=(600-x)*0.07;
 if(y<=450) y+=(450-y)*0.07;
 
 } 
 if (mouseX > x && mouseY < y) { 
 //b1 = 255;
 
 
 
 if(x>=200) x-=(x-200)*0.07;

 if(y<=450) y+=(450-y)*0.07;
 } 
 if (mouseX < x && mouseY > y) { 
 //b2 = 255;
 if(x<=600) x+=(600-x)*0.05; filter(INVERT);
 if(y>=150) y-=(y-150)*0.05;


 } 
 if (mouseX > x && mouseY > y) { 
 //b3 = 255;
 if(x>=200) x-=(x-200)*0.07;
 if(y>=150) y-=(y-150)*0.07;
 
 }
}
 
// Define Clock
class Clock {
 
 int h, m, s, d, m1, y;
 
 Clock() {
 }
 
 void getTime() {
 h = hour();
 m = minute();
 s = second();
 }
 void getDate(){
 d=day();
 m1=month();
 y=year();
 
 }
}
// Define Digitalclock
class DigitalClock extends Clock {
 int fontSize;
 float x, y;
 float x2, y2;
 int positionX, positionY;
 int positionx, positiony;
 int positionx2, positiony2;
 
 DigitalClock(int _fontSize, float _x, float _y, int _positionX, int _positionY, int _positionx, int _positiony, int _positionx2, int _positiony2) {
 fontSize = _fontSize;
 x = _x;
 y = _y;
 positionX = _positionX;
 positionY = _positionY;
 positionx = _positionx;
 positiony = _positiony;
 positionx2= _positionx2;
 positiony2= _positiony2;
 
 
 }
 
void getTime() {
 super.getTime();
}
void getDate(){
 super.getDate();
 }

void display() {
 fill(0);
 textSize(fontSize);
 textAlign(CENTER, CENTER);
 text(h + ":" + nf(m, 2) + ":" + nf(s, 2), positionX, positionY);
 //text(m1 + "/" + nf(d, 2) + "/" + nf(y, 4), positionx, positiony);
 text(String.valueOf(month()) +"/" + String.valueOf(day()) + "/" + String.valueOf(year()), positionx, positiony);
 textSize(32);
 text("SAN FRANCISCO", positionx2, positiony2); 
 fill(0, 102, 153);
 }
void display1() {
 fill(255);
 textSize(fontSize);
 textAlign(CENTER, CENTER);
 text (h+3 + ":" + nf(m, 2) + ":" + nf(s, 2), positionX, positionY);
 text(String.valueOf(month()) +"/" + String.valueOf(day()) + "/" + String.valueOf(year()), positionx, positiony);
 textSize(32);
 text("NEW YORK", positionx2, positiony2); 
 fill(0, 102, 153);
 }
void display2() {
 fill(255);
 textSize(fontSize);
 textAlign(CENTER, CENTER);
 text (h+2 + ":" + nf(m, 2) + ":" + nf(s, 2), positionX, positionY);
 text(String.valueOf(month()) +"/" + String.valueOf(day()) + "/" + String.valueOf(year()), positionx, positiony);
 textSize(32);
 text("CHICAGO", positionx2, positiony2); 
 fill(0, 102, 153);
 }
void display3() {
 fill(0);
 textSize(fontSize);
 textAlign(CENTER, CENTER);
 text (h+1 + ":" + nf(m, 2) + ":" + nf(s, 2), positionX, positionY);
 text(String.valueOf(month()) +"/" + String.valueOf(day()) + "/" + String.valueOf(year()), positionx, positiony);
 textSize(32);
 text("LAS VEGAS", positionx2, positiony2); 
 fill(0, 102, 153);
 }
 
}
 

Drop a comment

Your email address will not be published. Required fields are marked *