Tuesday, February 16, 2016

Clock Process #2


Added pulsing effects. One clock pulse every second, 2 on the minute, and three on the hour. Also added pulsing effects to each group to their corresponding times.

 I want to get an easing effect on the pulses, but I'm having some trouble. I currently tried it on the second pulse and got this (bold code), but it isn't working how I want it to.


// ---------- VARIABLES ----------

// ----- CLOCK VARIABLES -----
int cx, cy;
float secondsRadius;
float minutesRadius;
float hoursRadius;
float clockDiameter;
float fxs,fys;
float fxm,fym;
float fxh,fyh;

// ----- TIMER & EASING -----
float counter = 0;
float tdx = 15;
float tdy = 15;

float fdx = tdx;
float fdy = tdy;

int timer = 0;

// ----- PULSE VARIABLES -----
int secCheck;
int minCheck;
int hourCheck;


// ----------- SETUP ----------
void setup() {
  size(600, 600);
  background(0);
  
  int radius = min(width, height) / 2;
  secondsRadius = radius * 0.72;
  minutesRadius = radius * 0.60;
  hoursRadius = radius * 0.50;
  clockDiameter = radius * 1.8;
  
  cx = width / 2;
  cy = height / 2;
  
  fxs = width/2;
  fys = height/2;
  
}

// ---------- DRAW START ----------
// ---------- DRAW START ----------
// ---------- DRAW START ----------
void draw() {

  counter++;
 
  
  // ---------- CLOCK BACKGROUND ----------
  noFill();
  noStroke();
  ellipse(cx, cy, clockDiameter, clockDiameter);
  
  // Angles for sin() and cos() start at 3 o'clock;
  // subtract HALF_PI to make them start at the top
  float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
  float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI; 
  float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;
  
  
  
  // ---------- CLOCK HANDS ----------
  
  // ----- SECOND HAND -----
  strokeWeight(3);
  stroke(255,0,0);
  fxs += ((cx + cos(s) * secondsRadius) - fxs) * .03;
  fys += ((cy + sin(s) * secondsRadius) - fys) * .03;
  point(fxs+random(-10,10), fys+random(-10,10));
  
  // ----- MINUTE HAND -----
  stroke(255);  
  strokeWeight(3);
  fxm += ((cx + cos(m) * minutesRadius) - fxm) * .01;
  fym += ((cy + sin(m) * minutesRadius) - fym) * .01;
  point(fxm+random(-15,15), fym+random(-15,15));
  
  // ----- HOUR HAND -----
  strokeWeight(3);
  stroke(95,192,242);
  fxh += ((cx + cos(h) * hoursRadius) - fxh) * .1;
  fyh += ((cy + sin(h) * hoursRadius) - fyh) * .1;
 point(fxh+random(-20,20), fyh+random(-20,20));
  
  // ----- REFRESH -----
  fill(0,25);
  rect(0,0,width,height);
   
   
  
 // ---------- PULSES ----------
 
 timer++;
 fdx += (tdx - fdx) * .1;
 fdy += (tdy - fdy) * .1;
 
 // ----- SECOND PULSE -----
 if(secCheck != second()){
  //ll(255,0,0,100);
  stroke(255,0,0,100);
  ellipse(fxs,fys,fdx,fdy);
    if(secCheck != second()){
      tdx = 50;
      tdy = 50;
      timer = 0;
     }
     if (timer > 60){
       tdx = 15;
       tdy = 15;
   }
 }
   println(timer);
 
 // ----- CLOCK PULSE SEC -----
 int radius = min(width, height) / 2;
 if(secCheck != second()){
   noFill();
   stroke(random(255),random(255),random(255));
   ellipse(width/2,height/2,clockDiameter,clockDiameter);
 }
 secCheck = second();
 
 // ----- MINUTE PULSE -----
 if(minCheck != minute()){
   fill(255,255,255,100);
   noStroke();
   ellipse(fxm,fym,100,100);
 }

 // ----- CLOCK PULSE MIN ----- 
 if(minCheck != minute()){
   noFill();
   stroke(random(255),random(255),random(255));
   ellipse(width/2,height/2,clockDiameter+15,clockDiameter+15);
 }
  minCheck = minute();
  
 // ----- HOUR PULSE -----
  if(hourCheck != hour()){
   fill(0,0,255,100);
   noStroke();
   ellipse(fxh,fyh,150,150);
 }
 
 // ----- CLOCK PULSE HOUR -----
  if(hourCheck != hour()){
   noFill();
   stroke(random(255),random(255),random(255));
   ellipse(width/2,height/2,clockDiameter+25,clockDiameter+25);
 }
 hourCheck = hour();
  
}

1 comment:

  1. Brooke - very cool so far. But can you push this aesthetically? I'd love to see some of your signature style applied here... (remember you could totally import images!)

    ReplyDelete