I can't seem to get my minute and second tickers to move in this clock.

edited October 2017 in Questions about Code
color fill1 = (#324D9B);
color fill2 = (#4D65BC);
color fill3 = (#6476CC);
color fill4 = (#7C88E0);
color fill5 = (#8C94F2);
color fill6 = (#9DA9FC);
color fill7 = (#B6C2FF);
color fill8 = (#CCD6FF);

int s = second();
int m = minute();
int h = hour();

void setup() {
  size(800, 600);
}

void drawRects() {

  noStroke();
  fill(fill1);
  rect(0, 0, width * 1/8, height);
  fill(fill2);
  rect(width * 1/8, 0, width/8, height);
  fill(fill3);
  rect(width * 1/4, 0, width/8, height);
  fill(fill4);
  rect(width * 3/8, 0, width/8, height);
  fill(fill5);
  rect(width * 1/2, 0, width/8, height);
  fill(fill6);
  rect(width * 5/8, 0, width/8, height);
  fill(fill7);
  rect(width * 3/4, 0, width/8, height);
  fill(fill8);
  rect(width * 7/8, 0, width/8, height);
}

void draw() {

  //shift colors on hour
  if (h >= 0 && h < 3) {

    drawRects();
    fill1 = #324D9B;
    fill2 = #4D65BC;
    fill3 = #6476CC;
    fill4 = #7C88E0;
    fill5 = #8C94F2;
    fill6 = #9DA9FC;
    fill7 = #B6C2FF;
    fill8 = #CCD6FF;

    //draw second ticker
    stroke(0);
    strokeWeight(0.5);
    line(0, height/60 * s, width/8, height/60 * s);
  }

 if (h >= 3 && h < 6) {

    drawRects();
    fill1 = #4D65BC;
    fill2 = #324D9B;
    fill3 = #4D65BC;
    fill4 = #6476CC;
    fill5 = #7C88E0;
    fill6 = #8C94F2;
    fill7 = #9DA9FC;
    fill8 = #B6C2FF;

    //draw second ticker
    stroke(0);
    strokeWeight(0.5);
    line(width/8, height/60 * s, width/4, height/60 * s);
  }

  if (h >= 6 && h < 9) {
    println("Day-time!");

    drawRects();
    fill1 = #FFEB52;
    fill2 = #FFE72E;
    fill3 = #FFE200;
    fill4 = #FFE72E;
    fill5 = #FFEB52;
    fill6 = #FFEE6C;
    fill7 = #FFF28E;
    fill8 = #FFF5AA;

    //draw second ticker
    stroke(0);
    strokeWeight(0.5);
    line(width/4, height/60 * s, width * 3/8, height/60 * s);
  }

  if (h >= 9 && h < 12) {

    drawRects();
    fill1 = #FFEE6C;
    fill2 = #FFEB52;
    fill3 = #FFE72E;
    fill4 = #FFE200;
    fill5 = #FFE72E;
    fill6 = #FFEB52;
    fill7 = #FFEE6C;
    fill8 = #FFF28E;

    //draw second ticker
    stroke(0);
    strokeWeight(0.5);
    line(width * 3/8, height/60 * s, width/2, height/60 * s);
  }

  if (h >= 12 && h < 15) {

    drawRects();
    fill1 = #FFF28E;
    fill2 = #FFEE6C;
    fill3 = #FFEB52;
    fill4 = #FFE72E;
    fill5 = #FFE200;
    fill6 = #FFE72E;
    fill7 = #FFEB52;
    fill8 = #FFEE6C;

    //draw second ticker
    stroke(0);
    strokeWeight(0.5);
    line(width/2, height/60 * s, width * 5/8, height/60 * s);
  }

  if (h >= 15 && h < 18) {

    drawRects();
    fill1 = #FFF5AA;
    fill2 = #FFF28E;
    fill3 = #FFEE6C;
    fill4 = #FFEB52;
    fill5 = #FFE72E;
    fill6 = #FFE200;
    fill7 = #FFE72E;
    fill8 = #FFEB52;

    //draw second ticker
    stroke(0);
    strokeWeight(0.5);
    line(width * 5/8, height/60 * s, width * 3/4, height/60 * s);
  }

  if (h >= 18 && h < 21) {
    println("Night-time!");

    drawRects();
    fill1 = #B6C2FF;
    fill2 = #9DA9FC;
    fill3 = #8C94F2;
    fill4 = #7C88E0;
    fill5 = #6476CC;
    fill6 = #4D65BC;
    fill7 = #324D9B;
    fill8 = #4D65BC;

    //draw second ticker
    stroke(0);
    strokeWeight(0.5);
    line(width * 3/4, height/60 * s, width * 7/8, height/60 * s);
  }

  if (h >= 21 && h < 24) {

    drawRects();
    fill1 = #CCD6FF;
    fill2 = #B6C2FF;
    fill3 = #9DA9FC;
    fill4 = #8C94F2;
    fill5 = #7C88E0;
    fill6 = #6476CC;
    fill7 = #4D65BC;
    fill8 = #324D9B;

    //draw second ticker
    stroke(0);
    strokeWeight(0.5);
    line(width * 7/8, height/60 * s, width, height/60 * s);
  }

  //draw minute ticker
  stroke(0);
  strokeWeight(1);
  line((width/24 * h) + (width/1440 * m), 0, 
    (width/24 * h) + (width/1440 * m), height);

}

Answers

  • Maybe you want to change colors before calling drawRects()

    I can’t run your code here but for a classic pointer for second look at cos and sin and use map to calculate angle from s

  • turns out I had to just use second() instead of storing it in a variable

Sign In or Register to comment.