Clock Clock

Hello all, this is a (turns out) rather complicated clock program that I was inspired to create after I saw this a few months ago:

Here is my version, it changes 15 seconds before the turn of the minute.

clock

int radius = 120;
int lineradius=radius/2-3;
int[] cX= new int[24];
int[] cY= new int[24];
float[] time1c1r1= new float[10];
float[] time2c1r1= new float[10];
float[] time1c1r2= new float[10];
float[] time2c1r2= new float[10];
float[] time1c1r3= new float[10];
float[] time2c1r3= new float[10];
float[] time1c2r1= new float[10];
float[] time2c2r1= new float[10];
float[] time1c2r2= new float[10];
float[] time2c2r2= new float[10];
float[] time1c2r3= new float[10];
float[] time2c2r3= new float[10];

int prevSec; 
int prevMin;
int millisRolloverTime;

void setup() {
  size(1280, 720);
  for (int c=0; c<8; c++) {
    for (int r=0; r<3; r++) {
      int index = c+(8*r);
      cX[index]=(width/2)-(radius*4-radius/2)+(radius*c);
      cY[index]=(height/2)-radius+(radius*r);
    }
  }

  setTime();
  millisRolloverTime=0;
}

void draw() {
  background(#ffffff);
  fill(0);
  rect(width/2-radius/2, height/2-120, radius, radius*2);
  fill(#ffffff);
  noStroke();
  ellipse(width/2, height/2-radius/2, radius/2.68, radius/2.68);
  ellipse(width/2, height/2+radius/2, radius/2.68, radius/2.68);

  for (int i=0; i<24; i++) {
    stroke(0);
    strokeWeight(4); 
    fill(#ffffff);
    ellipse(cX[i], cY[i], radius, radius);
    strokeWeight(8);

    showTimeMove(i);
    //showTimeTogether(i);

    if (minute()+1==60) {
      println("Next min: 00");
    } else {
      println("Next min: "+(minute()+1));
    }
    if (hour()+1==24) {
      println("Next hr: 00");
    } else {
      println("Next hr: "+(hour()+1));
    }
  }
}

float backwards(float num) {
  float newnum = num;
  if (num==0) { 
    newnum= 0;
  }
  if (num==90) { 
    newnum= 270;
  }
  if (num==135) { 
    newnum= 225;
  }
  if (num==180) { 
    newnum= 180;
  }
  if (num==270) { 
    newnum= 90;
  }
  return newnum;
}

void showTimeMove(int i) {

  if (prevSec != second()) {
    millisRolloverTime = millis();
  } 
  prevSec = second();
  int mils = millis() - millisRolloverTime;
  float test = map(second() + mils/1000.0, 0, 60, 0, 360+(0));
  line(width/2, height/2-radius/2, width/2+cos(radians(test))*20, (height/2-radius/2)+(sin(radians(test))*20));
  line(width/2, height/2+radius/2, width/2+cos(radians(test))*20, (height/2+radius/2)+(sin(radians(test))*20));

  float animate = 0;
  int animationTime = 16;
  if (second()>=(60-animationTime)) {
    animate = (second()- (60-animationTime) + mils/1000.0);
  } else {  
    animate = 0;
  }



  int start = 135;
  int end = 225;
  test = -1*map(animate, 0, animationTime, -1*start, 360+end);
  //line(radius, radius, radius+cos(radians(test))*lineradius, radius+sin(radians(test))*lineradius);

  int digitH1=hour()/10;
  int digitH2=hour()%10;
  int digitM1=minute()/10;
  int digitM2=minute()%10;
  float coords; 
  float digitM1move;

  int hour = hour();
  int minute = minute();


  // FIRST DIGIT
  if (i==0) {
    if ((hour==9 || hour==19) && minute==59) {
      coords = map(animate, 0, animationTime, time1c1r1[digitH1], 1440+(time1c1r1[digitH1+1]));
    } else if (hour==23 && minute==59) {
      coords = map(animate, 0, animationTime, time1c1r1[digitH1], 1440+(time1c1r1[0]));
    } else {
      coords = map(animate, 0, animationTime, time1c1r1[digitH1], 1440+(time1c1r1[digitH1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if ((hour==9 || hour==19) && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r1[digitH1], 720+(backwards(time2c1r1[digitH1+1])));
    } else if (hour==23 && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r1[digitH1], 720+(backwards(time2c1r1[0])));
    } else {      
      coords = -1*map(animate, 0, animationTime, -1*time2c1r1[digitH1], 720+(backwards(time2c1r1[digitH1])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==1) {
    if ((hour==9 || hour==19) && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time1c2r1[digitH1], 720+(backwards(time1c2r1[digitH1+1])));
    } else if (hour==23 && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time1c2r1[digitH1], 720+(backwards(time1c2r1[0])));
    } else {      
      coords = -1*map(animate, 0, animationTime, -1*time1c2r1[digitH1], 720+(backwards(time1c2r1[digitH1])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if ((hour==9 || hour==19) && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c2r1[digitH1], 360+(backwards(time2c2r1[digitH1+1])));
    } else if (hour==23 && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c2r1[digitH1], 360+(backwards(time2c2r1[0])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time2c2r1[digitH1], 360+(backwards(time2c2r1[digitH1])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==8) {
    if ((hour==9 || hour==19) && minute==59) {
      coords = map(animate, 0, animationTime, time1c1r2[digitH1], 360+(time1c1r2[digitH1+1]));
    } else if (hour==23 && minute==59) {
      coords = map(animate, 0, animationTime, time1c1r2[digitH1], 360+(time1c1r2[0]));
    } else {
      coords = map(animate, 0, animationTime, time1c1r2[digitH1], 360+(time1c1r2[digitH1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if ((hour==9 || hour==19) && minute==59) {
      coords = map(animate, 0, animationTime, time2c1r2[digitH1], 720+(time2c1r2[digitH1+1]));
    } else if (hour==23 && minute==59) {
      coords = map(animate, 0, animationTime, time2c1r2[digitH1], 720+(time2c1r2[0]));
    } else {
      coords = map(animate, 0, animationTime, time2c1r2[digitH1], 720+(time2c1r2[digitH1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==9) {
    if ((hour==9 || hour==19) && minute==59) {
      coords = map(animate, 0, animationTime, time1c2r2[digitH1], 720+(time1c2r2[digitH1+1]));
    } else if (hour==23 && minute==59) {
      coords = map(animate, 0, animationTime, time1c2r2[digitH1], 720+(time1c2r2[0]));
    } else {
      coords = map(animate, 0, animationTime, time1c2r2[digitH1], 720+(time1c2r2[digitH1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if ((hour==9 || hour==19) && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c2r2[digitH1], 1080+(backwards(time2c2r2[digitH1+1])));
    } else if (hour==23 && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c2r2[digitH1], 1080+(backwards(time2c2r2[0])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time2c2r2[digitH1], 1080+(backwards(time2c2r2[digitH1])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==16) {
    if ((hour==9 || hour==19) && minute==59) {
      coords = map(animate, 0, animationTime, time1c1r3[digitH1], 720+(time1c1r3[digitH1+1]));
    } else if (hour==23 && minute==59) {
      coords = map(animate, 0, animationTime, time1c1r3[digitH1], 720+(time1c1r3[0]));
    } else {
      coords = map(animate, 0, animationTime, time1c1r3[digitH1], 720+(time1c1r3[digitH1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if ((hour==9 || hour==19) && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r3[digitH1], 720+(backwards(time2c1r3[digitH1+1])));
    } else if (hour==23 && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r3[digitH1], 720+(backwards(time2c1r3[digitH1+1])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r3[digitH1], 720+(backwards(time2c1r3[digitH1])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==17) {
    if ((hour==9 || hour==19) && minute==59) {
      coords = map(animate, 0, animationTime, time1c2r3[digitH1], 720+(time1c2r3[digitH1+1]));
    } else if (hour==23 && minute==59) {
      coords = map(animate, 0, animationTime, time1c2r3[digitH1], 720+(time1c2r3[0]));
    } else {
      coords = map(animate, 0, animationTime, time1c2r3[digitH1], 720+(time1c2r3[digitH1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if ((hour==9 || hour==19) && minute==59) {
      coords = map(animate, 0, animationTime, time2c2r3[digitH1], 1080+(time2c2r3[digitH1+1]));
    } else if (hour==23 && minute==59) {
      coords = map(animate, 0, animationTime, time2c2r3[digitH1], 1080+(time2c2r3[0]));
    } else {
      coords = map(animate, 0, animationTime, time2c2r3[digitH1], 1080+(time2c2r3[digitH1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }

  // SECOND DIGIT
  if (i==2) {
    if ((hour!=9 && hour!=19 && hour!=23) && minute==59) {
      coords = map(animate, 0, animationTime, time1c1r1[digitH2], 720+(time1c1r1[digitH2+1]));
    } else if ((hour==23 || hour==19 || hour==9) && minute==59) {
      coords = map(animate, 0, animationTime, time1c1r1[digitH2], 720+(time1c1r1[0]));
    } else {
      coords = map(animate, 0, animationTime, time1c1r1[digitH2], 720+(time1c1r1[digitH2]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if ((hour!=9 && hour!=19 && hour!=23) && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r1[digitH2], 720+(backwards(time2c1r1[digitH2+1])));
    } else if ((hour==23 || hour==19 || hour==9) && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r1[digitH2], 720+(backwards(time2c1r1[0])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r1[digitH2], 720+(backwards(time2c1r1[digitH2])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==3) {
    if ((hour!=9 && hour!=19 && hour!=23) && minute==59) {
      coords = map(animate, 0, animationTime, time1c2r1[digitH2], 720+(time1c2r1[digitH2+1]));
    } else if ((hour==23 || hour==19 || hour==9) && minute==59) {
      coords = map(animate, 0, animationTime, time1c2r1[digitH2], 720+(time1c2r1[0]));
    } else {
      coords = map(animate, 0, animationTime, time1c2r1[digitH2], 720+(time1c2r1[digitH2]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if ((hour!=9 && hour!=19 && hour!=23) && minute==59) {
      coords = map(animate, 0, animationTime, time2c2r1[digitH2], 1440+(time2c2r1[digitH2+1]));
    } else if ((hour==23 || hour==19 || hour==9) && minute==59) {
      coords = map(animate, 0, animationTime, time2c2r1[digitH2], 1440+(time2c2r1[0]));
    } else {
      coords = map(animate, 0, animationTime, time2c2r1[digitH2], 1440+(time2c2r1[digitH2]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==10) {
    if ((hour!=9 && hour!=19 && hour!=23) && minute==59) {
      coords = map(animate, 0, animationTime, time1c1r2[digitH2], 720+(time1c1r2[digitH2+1]));
    } else if ((hour==23 || hour==19 || hour==9) && minute==59) {
      coords = map(animate, 0, animationTime, time1c1r2[digitH2], 720+(time1c1r2[0]));
    } else {
      coords = map(animate, 0, animationTime, time1c1r2[digitH2], 720+(time1c1r2[digitH2]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if ((hour!=9 && hour!=19 && hour!=23) && minute==59) {
      coords = map(animate, 0, animationTime, time2c1r2[digitH2], 360+(time2c1r2[digitH2+1]));
    } else if ((hour==23 || hour==19 || hour==9) && minute==59) {
      coords = map(animate, 0, animationTime, time2c1r2[digitH2], 360+(time2c1r2[0]));
    } else {
      coords = map(animate, 0, animationTime, time2c1r2[digitH2], 360+(time2c1r2[digitH2]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==11) {
    if ((hour!=9 && hour!=19 && hour!=23) && minute==59) {
      coords = map(animate, 0, animationTime, time1c2r2[digitH2], 360+(time1c2r2[digitH2+1]));
    } else if ((hour==23 || hour==19 || hour==9) && minute==59) {
      coords = map(animate, 0, animationTime, time1c2r2[digitH2], 360+(time1c2r2[0]));
    } else {
      coords = map(animate, 0, animationTime, time1c2r2[digitH2], 360+(time1c2r2[digitH2]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if ((hour!=9 && hour!=19 && hour!=23) && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c2r2[digitH2], 720+(backwards(time2c2r2[digitH2+1])));
    } else if (digitH2==9 && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c2r2[digitH2], 720+(backwards(time2c2r2[0])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time2c2r2[digitH2], 720+(backwards(time2c2r2[digitH2])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==18) {
    if ((hour!=9 && hour!=19 && hour!=23) && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time1c1r3[digitH2], 720+(backwards(time1c1r3[digitH2+1])));
    } else if (digitH2==9 && minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time1c1r3[digitH2], 720+(backwards(time1c1r3[0])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time1c1r3[digitH2], 720+(backwards(time1c1r3[digitH2])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if ((hour!=9 && hour!=19 && hour!=23) && minute==59) {
      coords = map(animate, 0, animationTime, time2c1r3[digitH2], 1080+(time2c1r3[digitH2+1]));
    } else if (digitH2==9 && minute==59) {
      coords = map(animate, 0, animationTime, time2c1r3[digitH2], 1080+(time2c1r3[0]));
    } else {
      coords = map(animate, 0, animationTime, time2c1r3[digitH2], 1080+(time2c1r3[digitH2]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==19) {
    if ((hour!=9 && hour!=19 && hour!=23) && minute==59) {
      coords = map(animate, 0, animationTime, time1c2r3[digitH2], 1080+(time1c2r3[digitH2+1]));
    } else if ((hour==23 || hour==19 || hour==9) && minute==59) {
      coords = map(animate, 0, animationTime, time1c2r3[digitH2], 1080+(time1c2r3[0]));
    } else {
      coords = map(animate, 0, animationTime, time1c2r3[digitH2], 1080+(time1c2r3[digitH2]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if ((hour!=9 && hour!=19 && hour!=23) && minute==59) {
      coords = map(animate, 0, animationTime, time2c2r3[digitH2], 720+(time2c2r3[digitH2+1]));
    } else if ((hour==23 || hour==19 || hour==9) && minute==59) {
      coords = map(animate, 0, animationTime, time2c2r3[digitH2], 720+(time2c2r3[0]));
    } else {
      coords = map(animate, 0, animationTime, time2c2r3[digitH2], 720+(time2c2r3[digitH2]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }

  // THIRD DIGIT
  if (i==4) {
    if (digitM1!=5 && digitM2==9) {
      coords = map(animate, 0, animationTime, time1c1r1[digitM1], 720+(time1c1r1[digitM1+1]));
    } else if (minute==59) {
      coords = map(animate, 0, animationTime, time1c1r1[digitM1], 720+(time1c1r1[0]));
    } else {
      coords = map(animate, 0, animationTime, time1c1r1[digitM1], 720+(time1c1r1[digitM1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if (digitM1!=5 && digitM2==9) {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r1[digitM1], 1080+(backwards(time2c1r1[digitM1+1])));
    } else if (minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r1[digitM1], 1080+(backwards(time2c1r1[0])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r1[digitM1], 1080+(backwards(time2c1r1[digitM1])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==5) {
    if (digitM1!=5 && digitM2==9) {
      coords = map(animate, 0, animationTime, time1c2r1[digitM1], 720+(time1c2r1[digitM1+1]));
    } else if (minute==59) {
      coords = map(animate, 0, animationTime, time1c2r1[digitM1], 720+(time1c2r1[0]));
    } else {
      coords = map(animate, 0, animationTime, time1c2r1[digitM1], 720+(time1c2r1[digitM1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if (digitM1!=5 && digitM2==9) {
      coords = map(animate, 0, animationTime, time2c2r1[digitM1], 360+(time2c2r1[digitM1+1]));
    } else if (minute==59) {
      coords = map(animate, 0, animationTime, time2c2r1[digitM1], 360+(time2c2r1[0]));
    } else {
      coords = map(animate, 0, animationTime, time2c2r1[digitM1], 360+(time2c2r1[digitM1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==12) {
    if (digitM1!=5 && digitM2==9) {
      coords = -1*map(animate, 0, animationTime, -1*time1c1r2[digitM1], 1080+(backwards(time1c1r2[digitM1+1])));
    } else if (minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time1c1r2[digitM1], 1080+(backwards(time1c1r2[0])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time1c1r2[digitM1], 1080+(backwards(time1c1r2[digitM1])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if (digitM1!=5 && digitM2==9) {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r2[digitM1], 720+(backwards(time2c1r2[digitM1+1])));
    } else if (minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r2[digitM1], 720+(backwards(time2c1r2[0])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r2[digitM1], 720+(backwards(time2c1r2[digitM1])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==13) {
    if (digitM1!=5 && digitM2==9) {
      coords = -1*map(animate, 0, animationTime, -1*time1c2r2[digitM1], 720+(backwards(time1c2r2[digitM1+1])));
    } else if (minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time1c2r2[digitM1], 720+(backwards(time1c2r2[0])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time1c2r2[digitM1], 720+(backwards(time1c2r2[digitM1])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if (digitM1!=5 && digitM2==9) {
      coords = map(animate, 0, animationTime, time2c2r2[digitM1], 720+(time2c2r2[digitM1+1]));
    } else if (minute==59) {
      coords = map(animate, 0, animationTime, time2c2r2[digitM1], 720+(time2c2r2[0]));
    } else {
      coords = map(animate, 0, animationTime, time2c2r2[digitM1], 720+(time2c2r2[digitM1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==20) {
    if (digitM1!=5 && digitM2==9) {
      coords = -1*map(animate, 0, animationTime, -1*time1c1r3[digitM1], 720+(backwards(time1c1r3[digitM1+1])));
    } else if (minute==59) {
      coords = -1*map(animate, 0, animationTime, -1*time1c1r3[digitM1], 720+(backwards(time1c1r3[0])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time1c1r3[digitM1], 720+(backwards(time1c1r3[digitM1])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if (digitM1!=5 && digitM2==9) {
      coords = map(animate, 0, animationTime, time2c1r3[digitM1], 1080+(time2c1r3[digitM1+1]));
    } else if (minute==59) {
      coords = map(animate, 0, animationTime, time2c1r3[digitM1], 1080+(time2c1r3[0]));
    } else {
      coords = map(animate, 0, animationTime, time2c1r3[digitM1], 1080+(time2c1r3[digitM1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==21) {
    if (digitM1!=5 && digitM2==9) {
      coords = map(animate, 0, animationTime, time1c2r3[digitM1], 360+(time1c2r3[digitM1+1]));
    } else if (minute==59) {
      coords = map(animate, 0, animationTime, time1c2r3[digitM1], 360+(time1c2r3[0]));
    } else {
      coords = map(animate, 0, animationTime, time1c2r3[digitM1], 360+(time1c2r3[digitM1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if (digitM1!=5 && digitM2==9) {
      coords = map(animate, 0, animationTime, time2c2r3[digitM1], 720+(time2c2r3[digitM1+1]));
    } else if (minute==59) {
      coords = map(animate, 0, animationTime, time2c2r3[digitM1], 720+(time2c2r3[0]));
    } else {
      coords = map(animate, 0, animationTime, time2c2r3[digitM1], 720+(time2c2r3[digitM1]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }

  // FOURTH DIGIT
  if (i==6) {
    if (digitM2!=9) {
      coords = map(animate, 0, animationTime, time1c1r1[digitM2], 1440+(time1c1r1[digitM2+1]));
    } else {
      coords = map(animate, 0, animationTime, time1c1r1[digitM2], 1440+(time1c1r1[0]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if (digitM2!=9) {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r1[digitM2], 720+(backwards(time2c1r1[digitM2+1])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time2c1r1[digitM2], 720+(backwards(time2c1r1[0])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==7) {
    if (digitM2!=9) {
      coords = map(animate, 0, animationTime, time1c2r1[digitM2], 720+(time1c2r1[digitM2+1]));
    } else {
      coords = map(animate, 0, animationTime, time1c2r1[digitM2], 720+(time1c2r1[0]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if (digitM2!=9) {
      coords = map(animate, 0, animationTime, time2c2r1[digitM2], 360+(time2c2r1[digitM2+1]));
    } else {
      coords = map(animate, 0, animationTime, time2c2r1[digitM2], 360+(time2c2r1[0]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==14) {
    if (digitM2!=9) {
      coords = map(animate, 0, animationTime, time1c1r2[digitM2], 360+(time1c1r2[digitM2+1]));
    } else {
      coords = map(animate, 0, animationTime, time1c1r2[digitM2], 360+(time1c1r2[0]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if (digitM2!=9) {
      coords = map(animate, 0, animationTime, time2c1r2[digitM2], 720+(time2c1r2[digitM2+1]));
    } else {
      coords = map(animate, 0, animationTime, time2c1r2[digitM2], 720+(time2c1r2[0]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==15) {
    if (digitM2!=9) {
      coords = -1*map(animate, 0, animationTime, -1*time1c2r2[digitM2], 720+(backwards(time1c2r2[digitM2+1])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time1c2r2[digitM2], 720+(backwards(time1c2r2[0])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if (digitM2!=9) {
      coords = -1*map(animate, 0, animationTime, -1*time2c2r2[digitM2], 360+(backwards(time2c2r2[digitM2+1])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time2c2r2[digitM2], 360+(backwards(time2c2r2[0])));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==22) {
    if (digitM2!=9) {
      coords = -1*map(animate, 0, animationTime, -1*time1c1r3[digitM2], 360+(backwards(time1c1r3[digitM2+1])));
    } else {
      coords = -1*map(animate, 0, animationTime, -1*time1c1r3[digitM2], 360+(time1c1r3[0]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if (digitM2!=9) {
      coords = map(animate, 0, animationTime, time2c1r3[digitM2], 720+(time2c1r3[digitM2+1]));
    } else {
      coords = map(animate, 0, animationTime, time2c1r3[digitM2], 720+(time2c1r3[0]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
  if (i==23) {
    if (digitM2!=9) {
      coords = map(animate, 0, animationTime, time1c2r3[digitM2], 1080+(time1c2r3[digitM2+1]));
    } else {
      coords = map(animate, 0, animationTime, time1c2r3[digitM2], 1080+(time1c2r3[0]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
    if (digitM2!=9) {
      coords = map(animate, 0, animationTime, time2c2r3[digitM2], 360+(time2c2r3[digitM2+1]));
    } else {
      coords = map(animate, 0, animationTime, time2c2r3[digitM2], 360+(time2c2r3[0]));
    }
    line(cX[i], cY[i], cX[i]+cos(radians(coords))*lineradius, cY[i]+sin(radians(coords))*lineradius);
  }
}

void setTime() {
  int d;
  d=0;//SET TIME = 0
  time1c1r1[d] = 0;
  time2c1r1[d] = 90;
  time1c1r2[d] = 270;
  time2c1r2[d] = 90;
  time1c1r3[d] = 270;
  time2c1r3[d] = 0;
  time1c2r1[d] = 180;
  time2c2r1[d] = 90;
  time1c2r2[d] = 270;
  time2c2r2[d] = 90;
  time1c2r3[d] = 270;
  time2c2r3[d] = 180;

  d=1;//SET TIME = 1
  time1c1r1[d] = 135;
  time2c1r1[d] = 135;
  time1c1r2[d] = 135;
  time2c1r2[d] = 135;
  time1c1r3[d] = 135;
  time2c1r3[d] = 135;
  time1c2r1[d] = 90;
  time2c2r1[d] = 90;
  time1c2r2[d] = 270;
  time2c2r2[d] = 90;
  time1c2r3[d] = 270;
  time2c2r3[d] = 270;

  d=2;//SET TIME = 2
  time1c1r1[d] = 0;
  time2c1r1[d] = 0;
  time1c1r2[d] = 0;
  time2c1r2[d] = 90;
  time1c1r3[d] = 270;
  time2c1r3[d] = 0;
  time1c2r1[d] = 180;
  time2c2r1[d] = 90;
  time1c2r2[d] = 270;
  time2c2r2[d] = 180;
  time1c2r3[d] = 180;
  time2c2r3[d] = 180;

  d=3;//SET TIME = 3
  time1c1r1[d] = 0;
  time2c1r1[d] = 0;
  time1c1r2[d] = 0;
  time2c1r2[d] = 0;
  time1c1r3[d] = 0;
  time2c1r3[d] = 0;
  time1c2r1[d] = 180;
  time2c2r1[d] = 90;
  time1c2r2[d] = 270;
  time2c2r2[d] = 180;
  time1c2r3[d] = 270;
  time2c2r3[d] = 180;

  d=4;//SET TIME = 4
  time1c1r1[d] = 90;
  time2c1r1[d] = 90;
  time1c1r2[d] = 270;
  time2c1r2[d] = 0;
  time1c1r3[d] = 135;
  time2c1r3[d] = 135;
  time1c2r1[d] = 90;
  time2c2r1[d] = 90;
  time1c2r2[d] = 270;
  time2c2r2[d] = 90;
  time1c2r3[d] = 270;
  time2c2r3[d] = 270;

  d=5;//SET TIME = 5
  time1c1r1[d] = 0;
  time2c1r1[d] = 90;
  time1c1r2[d] = 270;
  time2c1r2[d] = 0;
  time1c1r3[d] = 0;
  time2c1r3[d] = 0;
  time1c2r1[d] = 180;
  time2c2r1[d] = 180;
  time1c2r2[d] = 180;
  time2c2r2[d] = 90;
  time1c2r3[d] = 270;
  time2c2r3[d] = 180;

  d=6;//SET TIME = 6
  time1c1r1[d] = 0;
  time2c1r1[d] = 90;
  time1c1r2[d] = 270;
  time2c1r2[d] = 90;
  time1c1r3[d] = 270;
  time2c1r3[d] = 0;
  time1c2r1[d] = 180;
  time2c2r1[d] = 180;
  time1c2r2[d] = 180;
  time2c2r2[d] = 90;
  time1c2r3[d] = 270;
  time2c2r3[d] = 180;

  d=7;//SET TIME = 7
  time1c1r1[d] = 0;
  time2c1r1[d] = 0;
  time1c1r2[d] = 135;
  time2c1r2[d] = 135;
  time1c1r3[d] = 135;
  time2c1r3[d] = 135;
  time1c2r1[d] = 180;
  time2c2r1[d] = 90;
  time1c2r2[d] = 270;
  time2c2r2[d] = 90;
  time1c2r3[d] = 270;
  time2c2r3[d] = 270;

  d=8;//SET TIME = 8
  time1c1r1[d] = 0;
  time2c1r1[d] = 90;
  time1c1r2[d] = 270;
  time2c1r2[d] = 0;
  time1c1r3[d] = 270;
  time2c1r3[d] = 0;
  time1c2r1[d] = 180;
  time2c2r1[d] = 90;
  time1c2r2[d] = 270;
  time2c2r2[d] = 180;
  time1c2r3[d] = 270;
  time2c2r3[d] = 180;

  d=9;//SET TIME = 9
  time1c1r1[d] = 0;
  time2c1r1[d] = 90;
  time1c1r2[d] = 270;
  time2c1r2[d] = 0;
  time1c1r3[d] = 135;
  time2c1r3[d] = 135;
  time1c2r1[d] = 180;
  time2c2r1[d] = 90;
  time1c2r2[d] = 270;
  time2c2r2[d] = 90;
  time1c2r3[d] = 270;
  time2c2r3[d] = 270;
}

void showTimeTogether(int i) {
  int digit=second()%10;
  //SET TIME BY ROW AND COLUMN
  if (i%2!=0) {
    if (i<8) {
      line(cX[i], cY[i], cX[i]+cos(radians(time1c2r1[digit]))*lineradius, cY[i]+sin(radians(time1c2r1[digit]))*lineradius);
      line(cX[i], cY[i], cX[i]+cos(radians(time2c2r1[digit]))*lineradius, cY[i]+sin(radians(time2c2r1[digit]))*lineradius);
    } else if (i>=8 && i<16) {
      line(cX[i], cY[i], cX[i]+cos(radians(time1c2r2[digit]))*lineradius, cY[i]+sin(radians(time1c2r2[digit]))*lineradius);
      line(cX[i], cY[i], cX[i]+cos(radians(time2c2r2[digit]))*lineradius, cY[i]+sin(radians(time2c2r2[digit]))*lineradius);
    } else {
      line(cX[i], cY[i], cX[i]+cos(radians(time1c2r3[digit]))*lineradius, cY[i]+sin(radians(time1c2r3[digit]))*lineradius);
      line(cX[i], cY[i], cX[i]+cos(radians(time2c2r3[digit]))*lineradius, cY[i]+sin(radians(time2c2r3[digit]))*lineradius);
    }
  } else {
    if (i<8) {
      line(cX[i], cY[i], cX[i]+cos(radians(time1c1r1[digit]))*lineradius, cY[i]+sin(radians(time1c1r1[digit]))*lineradius);
      line(cX[i], cY[i], cX[i]+cos(radians(time2c1r1[digit]))*lineradius, cY[i]+sin(radians(time2c1r1[digit]))*lineradius);
    } else if (i>=8 && i<16) {
      line(cX[i], cY[i], cX[i]+cos(radians(time1c1r2[digit]))*lineradius, cY[i]+sin(radians(time1c1r2[digit]))*lineradius);
      line(cX[i], cY[i], cX[i]+cos(radians(time2c1r2[digit]))*lineradius, cY[i]+sin(radians(time2c1r2[digit]))*lineradius);
    } else {
      line(cX[i], cY[i], cX[i]+cos(radians(time1c1r3[digit]))*lineradius, cY[i]+sin(radians(time1c1r3[digit]))*lineradius);
      line(cX[i], cY[i], cX[i]+cos(radians(time2c1r3[digit]))*lineradius, cY[i]+sin(radians(time2c1r3[digit]))*lineradius);
    }
  }
}

Thousand Lines: (Another) Mandala

Another mandala, similar to my clock mandala…Semi-unpredictable patterns created by mashing variables and loops around. It can be spun with the mouse (and there’s some simple smoothing so you can kind of ‘throw’ it).

At a Loss

This morning I, realized I had been spending way too much money. I began to relate my spending habits with the days of the week and realized that tracking the amount of money I had spent would be a perfect way for me to tell how far along into the week we are. Originally I aimed to make this in java processing, but python was much more receptive to the list structure I wanted to use, so I switched to python mode.

Here is a snapshot of September 24th at 4:44
WednesdayOctFirst444

And here is a snapshot of today, October 1st at 4:45
WednesdayOct8445

sun = []
mon = [10.56, 9.10, 19.68, 5.62, 7.39]
tue = [7.27, 6.75, 8.85, 7.39]
wed = [7.39, 7.39, 2.85]
thu = [2.00, 6.75, 13.75]
fri = [6.75, 9.08, 9.08]
sat = [7.27, 6.75, 8.85, 7.39]

sunTot = 0
monTot = 0
tueTot = 0
wedTot = 0
thuTot = 0
friTot = 0
satTot = 0

sunAvg = 0
monAvg = 0
tueAvg = 0
wedAvg = 0
thuAvg = 0
friAvg = 0
satAvg = 0

weekTot = 0
weekAvg = 0

sunLoss = 0
monLoss = 0
tueLoss = 0
wedLoss = 0
thuLoss = 0
friLoss = 0
satLoss = 0

lossList = []

todayTotal = 0
lossPerSecond = 0

dayLoss = 0

previousDayLoss = 0

startingCash = 0

totalLoss = 0
currentCash = 0

def setup():
    size(800,300)
    startingCash = 240 #Dollars
    initialize() 
    previousDayLoss = cashUsed()
    
def initialize():
    sunTot = total(sun)
    monTot = total(mon)
    tueTot = total(tue)
    wedTot = total(wed)
    thuTot = total(thu)
    friTot = total(fri)
    satTot = total(sat)

    weekList = [sunTot, monTot, tueTot, wedTot, thuTot, friTot, satTot]
    weekTot = total(weekList)

    sunAvg = sunTot / weekTot
    monAvg = monTot / weekTot
    tueAvg = tueTot / weekTot
    wedAvg = wedTot / weekTot
    thuAvg = thuTot / weekTot
    friAvg = friTot / weekTot
    satAvg = satTot / weekTot
    weekAvg = weekTot / 7.0

    sunLoss = sunAvg * startingCash
    monLoss = monAvg * startingCash
    tueLoss = tueAvg * startingCash
    wedLoss = wedAvg * startingCash
    thuLoss = thuAvg * startingCash
    friLoss = friAvg * startingCash
    satLoss = satAvg * startingCash
    
    lossList = [sunLoss, monLoss, tueLoss, wedLoss, thuLoss, friLoss, satLoss]
    
    todayTotal = lossList[dayOfWeek()]
    lossPerSecond = todayTotal / 86400
    
    
def draw():
    background(findBg())
    dayLoss = ((((hour() * 60) + minute()) * 60) + second()) * lossPerSecond
    totalLoss = previousDayLoss + dayLoss
    currentCash = startingCash - totalLoss
    printCash()

def total(alist):
    total = 0
    for i in alist:
        total += i
    return total

def dayOfWeek():
    # 5 is number of days into 2014 for sunday
    daystotal = (365*(year() - 1)) + (int(floor((year()-1)/4))) -(int(floor((year() - 1)/100))) + (int(floor((year() - 1)/400))) + day()
    return daystotal % 7

def week():
    return month() * 4 + day() % 7 

def cashUsed():
    w = week()
    d = dayOfWeek()
    daysElapsed = (w % 2) * 7 + d - 1 
    loss = 0
    for i in range(daysElapsed):
        loss += lossList[i%7] / 2
    return loss

def findBg():
    return map(255.0 * ((((week() % 2) * 7) + dayOfWeek()) / 14.0),255,0,0,255) \
             + map(hour()+8,24,0,0,18)
             
def printCash():
    textAlign(CENTER)
    cashLeft = "%f" % currentCash
    fill(100)
    textSize(width * .20)
    lost = nfs(totalLoss,3,2)
    text("$"+lost,width*.505, height*.71)
    
    fill(255,0,0)
    stroke(0)
    
    textSize(width * .20)
    lost = nfs(totalLoss,3,2)
    text("$"+lost,width*.5, height*.7)
    
        
    

Alex Thousand Liner

Rain Bow

For this prompt, I wanted it to rain and every time. your mouse was over a raindrop, It would change color. I was successfully able to create 100o falling rain drops and make them change color when the mouse was on one. However, I did not know how to make the drops fall at different intervals
so they all fall together. If I would work more on this project I would have them fall at different intervals and possibly have them avoid the cursor.

int radius = 2;
float y = -radius;
float speed = 3;
void setup() {
  size(1000, 200);
  smooth();
}
void draw() {
  float r=random(0,255);
float g=random(0,255);
float b=random(0,255);

   fill(50,50,50,10);
  rect(0,0,1000,200); 
  
  y += speed;
  if (y > height) {
y = -radius;
}
for (int i=2; i< =1000; i+=2) {
  line(i,y, i,y-5);
    if((mouseX>i) && (mouseX

Ten Liners

Soon, he multiplied. Gathering new companions upon his plane, our one was now many. Together they inhabited the two-dimensional world they had been handed, but now they gained a true sense of ownership. One is timid, many are strong. Together they observe any and all intruders on their plain. They seek the knowledge their intruders hold.

import java.awt.Robot;
import java.awt.AWTException;
import processing.serial.*;
import java.awt.MouseInfo;
import java.awt.Point;

Robot rob;

boolean allAlerted;
ArrayList<LineMan> lineList;
ArrayList<Position> atkPosList;
ArrayList<Position> restPosList;
ArrayList<Position> mouseHits;
int lastUpdate;
int timeWait;
boolean oneAlerted;

void setup() {
  size(800,600);
  cursor(HAND);
  
  //Set up Bot to move mouse
  try {
  rob = new Robot();
  }
  catch (AWTException e) {
    e.printStackTrace();
  }
  mouseHits = new ArrayList<Position>();
  updateAtkPositions();
  createRestPositions();
  createLines();
  allAlerted = false;
  lastUpdate = 0;
  oneAlerted = false;
  
}

void draw() {
  background(255);
  updatePositions();
  mouseChecks();
  updateLines();
  drawLines();
}

void keyPressed() {
  //Get x,y of frame to offset changes. 
  int x = frame.getLocation().x;
  int y = frame.getLocation().y;
  rob.mouseMove(x +  width/2, y + height/2);
}

void mouseChecks() {
  if (mouseInWindow() && !oneAlerted) {
    oneAlerted = true;
    alertClosest();
  } else if (!mouseInWindow()) {
    oneAlerted = false;
    ignoreMouse();
  }
  checkAlerted();
}

boolean mouseInWindow() {
  Point mousePos = (MouseInfo.getPointerInfo().getLocation());
  int mWinX = mousePos.x;
  int mWinY = mousePos.y;
  int fX = frame.getLocation().x;
  int fY = frame.getLocation().y;
  if ((mWinX > fX && mWinX < fX + width) &&
     (mWinY > fY && mWinY < fY + height)) {
   return true;
  } else {
   return false;
  } 
}

void alertClosest() {
  int closest = 0;
  int closestD = width;
  for (int i = 0; i < 10; i++) {
    if (dist(mouseX, mouseY, lineList.get(i).x, lineList.get(i).y) < closestD) {
      closest = i;
    }
  }
  lineList.get(closest).alerted = true;
}

void ignoreMouse() {
  for (int i = 0; i < 10; i++) {
    lineList.get(i).alerted = false;
  }
}

void updatePositions() {
  updateAtkPositions();
  if ((millis() - lastUpdate)/1000.0 >= 1.5) {
    lastUpdate = millis();
    updateRestPositions();
  }
}

void checkAlerted() {
  boolean check = true;
  for (int i = 0; i < 10; i++) {
    if (lineList.get(i).alerted == false) {
      check = false;
      allAlerted = false;
      break;
    }
  }
  if ((check)) {
      allAlerted = true;
  }
}

      
void createLines() {
  lineList = new ArrayList<LineMan>();
  for (int i = 0; i < 10; i++) {
    float x = random(width*.1, width*.9);
    float y = random(height * .1, height * .9);
    lineList.add(new LineMan(x,y,i));
  }
}

void updateAtkPositions() { 
  atkPosList = new ArrayList<Position>();
  float r = width * .07; // radius around mouse
  for (int i = 0; i < 10; i++) {
    float theta = i * (6.28 / 10 );
    atkPosList.add(new Position(mouseX + (r * cos(theta)), mouseY + (r * sin(theta)) ) );
// This Code shows the attack positions
//    strokeWeight(5);
//    point(mouseX + r * cos(theta),mouseY +  r * sin(theta));
  }
}

void createRestPositions() {
  restPosList = new ArrayList<Position>();
  for (int i = 0; i < 10; i++) {
    float x = random(width * .15, width * .85);
    float y = random(height * .15, height * .85);
    restPosList.add(new Position(x,y));
  }
  
}

void updateRestPositions() {
  for (int i = 0; i < 10; i++) {
    if (random(10) < 2) {
      restPosList.get(i).x = random(width*.15, width*.85);
      restPosList.get(i).y = random(height*.15,width*.85);
    }
  }
}

void updateLines() {
  int count = 0;
  for (int i = 0; i < 10; i++) { 
    lineList.get(i).update();
    if (lineList.get(i).alerted){
      count += 1;
    }
  }
}

void drawLines() {
  for (int i = 0; i < 10; i++) {
    lineList.get(i).drawMe();
  }
}
    

class LineMan {
  float x;
  float y;
  float lineLength;
  float thickness;
  float headX;
  float headY;
  float bottomX;
  float bottomY;
  float distance;
  int index;
  float speed;
  Position atkPos;
  Position restPos;
  boolean attacking;
  boolean alerted;
  boolean inPlace;
  float yChange;
  float sinCurve;
  float sinCurveChange;
  float cosCurve;
  float cosCurveChange;
  float xChange;
  
  LineMan(float x,float y,int index) {
    this.x = x;
    this.y = y;
    this.lineLength = (int)random(height * .05, height * .1);
    this.thickness = (int)random(2, 5);
    this.speed = max(width/4, height/4)/(this.lineLength * this.thickness); //Fatter lines move slower. 
    this.headX = x; 
    this.headY = y - lineLength/2;
    this.bottomX = x;
    this.bottomY = y + lineLength/2;
    this.alerted = false;
    this.update();
    this.sinCurveChange = .1;
    this.cosCurveChange = 0;
    this.index = index;
    this.sinCurve = random(0, 6.28);
    this.cosCurve = random(0, 6.28);
  }
  
  void drawMe() {
    strokeWeight(this.thickness);
    line(this.bottomX, this.bottomY, this.headX, this.headY);
  }
  
  void update() {
    if ((allAlerted)) {
      this.attacking = true;
    } else {
      this.attacking = false;
    } 
    
    this.sinCurve += this.sinCurveChange;
    this.sinCurve = this.sinCurve % 6.28;
    this.cosCurve += this.cosCurveChange;
    this.cosCurve = this.cosCurve % 6.28;
    float coEff;
    float xCoEff;
    
    if ((this.alerted) && (!this.attacking)) {
      coEff = .2; //Slow
      xCoEff = 2;
      this.cosCurveChange = .3; //Side to Side Motion
    } else if ((this.attacking) && (!this.inPlace)){
      coEff = 10; //Fast
      xCoEff = 2;
      this.cosCurveChange = .3; //Side to Side Motion;
    } else if ((this.attacking) && (this.inPlace)) {
      coEff = 2; //Sort of Slow
      xCoEff = 2;
      this.cosCurveChange = .1; //Side to Side Motion;
    } else {
      coEff = 5; //No one on screen
      xCoEff = 0;
     this.cosCurveChange = 0; //Side to Side Motion
    }
    
    if (this.alerted) {
      this.alertBuddy();
    }
    
    // CoEff... offset by height of window... sin wave
    this.yChange = coEff * (height / (float)400) * sin(this.sinCurve); 
    this.xChange = xCoEff * (width / (float)400) * (cos(this.cosCurve));
    this.definePos();
    this.move();
  }
  
  void definePos() {
    this.atkPos = atkPosList.get(this.index);
    this.restPos = restPosList.get(this.index); 
    if (this.attacking) {
      if ((abs(this.x - this.atkPos.x) <= width*.02) &&
          (abs(this.y - this.atkPos.y) <= height*.02)) {
        this.inPlace = true;
      } else {
        this.inPlace = false;
      }
    } else {
      if ((abs(this.x - this.restPos.x) <= width * .02) &&
          (abs(this.y - this.restPos.y) <= height * .02)){
        this.inPlace = true;
          } else {
        this.inPlace = false;
          }
    }
  }
  
  void move() {
    if ((this.attacking) && (!this.inPlace)){
      float distance = dist(this.x, this.y, this.atkPos.x, this.atkPos.y);
      this.x += this.speed*(-((this.x - this.atkPos.x)/distance));
      this.y += this.speed*(-((this.y - this.atkPos.y)/distance));
    } else if ((!this.attacking) && (!this.inPlace)){
      float distance = dist(this.x, this.y, this.restPos.x, this.restPos.y);
      this.x += this.speed*(-((this.x - this.restPos.x)/distance));
      this.y += this.speed*(-((this.y - this.restPos.y)/distance));
    }
    this.headX = this.x + this.xChange; 
    this.headY = (this.y - lineLength/2) + this.yChange;
    this.bottomX = this.x + this.xChange;
    this.bottomY = this.y + lineLength/2 + this.yChange;
  }
  
  void alertBuddy() {
    if (random(10) < .5) {
      lineList.get((int)random(10)).alerted = true;
    }
  }
    
}

class Position {
  float x;
  float y;
  
  Position(float x, float y) {
    this.x = x;
    this.y = y;
  }
}

One Liner

I did not want to create lines, I wanted to create beings. I wanted to be God. And so I was. I examined my creatures and the results surprised me. (Not really, I built them this way.)

In the beginning there was one. Created in my visage, but left to his own thoughts and devices. A free will of sorts. In his plane, he roams unaware of the outside world. When encroached upon, he is shy, timid, and afraid. Alone, he runs, hiding from intruders until he may return safely to his plane.

import java.awt.MouseInfo;
import java.awt.Point;

LineMan guy;
boolean mouseInFrame;
int lastMouseX;
int lastMouseY;

void setup() {
  size(800,600);
  lastMouseX = 0;
  lastMouseY = 0;
  mouseInFrame = false;
  guy = new LineMan(width/2, height/2);
}

void draw() {
  background(255);
  checkForMouse();
  guy.update();
  guy.drawMe();
}

void checkForMouse() {
  Point mousePos = (MouseInfo.getPointerInfo().getLocation());
  int mWinX = mousePos.x;
  int mWinY = mousePos.y;
  int fX = frame.getLocation().x;
  int fY = frame.getLocation().y;
  if ((mWinX > fX && mWinX < fX + width) &&
     (mWinY > fY && mWinY < fY + height)) {
   mouseInFrame = true;
  } else {
   mouseInFrame = false;
  } 
  if (lastMouseX != mouseX){
    lastMouseX = mouseX;
  }
  if (lastMouseY != mouseY) {
    lastMouseY = mouseY;
  }
}

class LineMan {
  float x;
  float y;
  float lineLength;
  float thickness;
  float headX;
  float headY;
  float bottomX;
  float bottomY;
  float hoverValue;
  float shakeValue;
  float speed;
  boolean inPlace;
  float shakeChange;
  boolean noRelocate;
  Position target;
  int lastSeenX; 
  int lastSeenY;
  float scared;
  float originalSpeed;
  
  LineMan(float x, float y) {
   this.lastSeenX = 0;
   this.lastSeenY = 0;
   
   this.x = x;
   this.y = y;
   
   this.lineLength = random(height*.05, height*.1);
   this.thickness = random(width*.005, width*.01);
   
   this.originalSpeed = (max(width * .2 , height * .2) / (this.lineLength * this.thickness));
   this.speed = this.originalSpeed;
   
   this.headX = x;
   this.headY = y - this.lineLength / 2;
   
   this.bottomX = x;
   this.bottomY = y + this.lineLength /2;
   
   this.hoverValue = random(0, 6.28);
   this.shakeValue = random(0, 6.28);
   
   this.shakeChange = .1;
   this.inPlace = false;
   
   this.scared = 1;
   
   target = new Position(width * .1, width * .9, height * .1, height *.9);
  }
  
  void move() {
      float distance = dist(this.x, this.y, this.target.x, this.target.y);
      if (distance < (max(width,height) * .05)) {
        this.inPlace = true;
      } else {
        this.inPlace = false;
      }
      if (!this.inPlace) {
          this.x += this.speed *  -((this.x - this.target.x)/distance);
          this.y += this.speed *  -((this.y - this.target.y)/distance);
      } 
    this.headX = this.x; 
    this.headY = this.y - lineLength/2;
    this.bottomX = this.x;
    this.bottomY = this.y + lineLength/2;
  }
  
  void hover() {
    float xChange = cos(this.shakeValue) * (width * .02);
    float yChange = sin(this.hoverValue) * (height * .02);
    this.headX += xChange;
    this.bottomX += xChange;
    this.headY += yChange;
    this.bottomY += yChange;
    this.hoverValue = (this.hoverValue + this.shakeChange) % 6.28;

  }
  
  void drawMe() {
    strokeWeight(this.thickness);
    line(headX,headY, bottomX, bottomY);
  }
  
  void relocate() {
    float distance;
    float erratic = .1; // bigger value means more erratic behavior. 
    if (mouseInFrame) { // Relocate on screen to a new position if the mouse is on screen
    //These Changes will be erratic and make the line look scared.
      if ((random(10) < erratic) || (lastMouseX != this.lastSeenX || lastMouseY != this.lastSeenY)) {
        this.lastSeenX = lastMouseX;
        this.lastSeenY = lastMouseY;
          if (mouseY < height / 2) { // Top half
            if (mouseX < width/2) { //left
              this.target = new Position(width/2, width, height/2, height); //bottom right
            } else { // right
              this.target = new Position(0, width/2, height/2, height); // bottom left
            }
          } else { //Bottom Half
            if (mouseX < width/2) { //left
              this.target = new Position(width/2, width, 0, height/2); // top Right
            } else { //right
              this.target = new Position(0, width/2, 0, height/2); // top left
            }
          }
      }
    } else { 
      float chance = .1; // Bigger values means more relocation when mouse off screen.
      if (random(10) < chance) { // Relocate in the window sometimes 
        this.target = new Position(width * .1, width * .9, height * .1, height * .9);
      }
    }
  } 

  void worry() {
   if (mouseInFrame) {
      this.shakeValue = (this.shakeValue + (this.shakeChange * this.scared)) % 6.28;
      if (!(this.speed >= this.originalSpeed * 2)) {
        this.speed *= 1.01;
      }
      if (!(this.scared >= 3)) {
        this.scared *= 1.01;
      }
    } else {
        if (!(this.scared <= 1)) {
          this.scared *= .999;
        }
        if (!(this.shakeValue <= .1)) {
          this.shakeValue -= .005;
        }
        if (!(this.speed <= this.originalSpeed)) {
          this.speed *= .999;
        }
      }
  }  
  
  void update() {
    this.worry();
    this.move();
    this.hover();
    this.relocate();
  }
    
}

class Position {
    float x;
    float y;
    
    Position(float startX, float endX, float startY, float endY) {
      this.x = random(startX, endX);
      this.y = random(startY, endY);
    }
}

Waves of light, over a light, reflected off a pool of water.

My personal clock utilized layered rectangles traveling across two bars at the top of the screen. As a minute goes by, the bars will meet in the middle and continue across the screen in a wave-like motion. The minutes of the hour are represented by a lighter rectangle that moves across each bar in a similar fashion. The hour is not specifically shown. However, the lamp will be displayed lighter in the daytime and darker as nighttime approaches.

 

2:54 PMScreen Shot 2014-10-01 at 2.54.09 PM

2:54 PMScreen Shot 2014-10-01 at 2.54.25 PM

5:42 PMScreen Shot 2014-10-01 at 5.42.17 PM

5:42 PMScreen Shot 2014-10-01 at 5.42.41 PM

 

//Will Taylor
//EMS clock
float tintR = 100;
float tintG = 100;
float tintB = 100;

void setup(){
PImage bg = loadImage("bridgeLight.jpg");
size(bg.width, bg.height);
drawClock();
frameRate(20);
smooth();

}

void draw(){
float s = second();
float m = minute();
float h = hour();
float sec = map(s,0,59, 0,width);
float sec2 = map(s,0,59, width,0);
float min = map(m,0,59, 0,width);
float min2 = map(m,0,59, width,0);
//drawClock();

float alphaS = 2;
float alphaM = 1;
//noStroke();

// MINUTES //
if (s%2 == 0) {
fill(#C2BCDB, alphaM);
} else {
fill(#FF05C5, alphaM);
}

rect(min, width/13 + 5, width/30, 50);
rect(min, width/23 + 5, width/30,50);

rect(min2, width/7 + 5, width/30, 50);
rect(min2, width/6 + 14, width/30,50);

// SECONDS //
if (s%2 == 0) {
fill(#FC08D4, alphaS);
} else {
fill(#08C9FC, alphaS);
}

if (s >=30){
alphaS = 6;
println(alphaS);
}
float secX = 0; float secY = width/13;
rect(sec, width/13 + 5, width/30, 50);
rect(sec, width/23 + 5, width/30,50);
rect(sec2, width/13 + 5, width/30, 50);
rect(sec2, width/23 + 5, width/30,50);

if (s%2 == 0) {
fill(#08C9FC, alphaS);
} else {
fill(#FC08D4, alphaS);
}
rect(sec, width/7 + 5, width/30, 50);
rect(sec, width/6 + 14, width/30,50);
rect(sec2, width/7 + 5, width/30, 50);
rect(sec2, width/6 + 14, width/30,50);

if (second()== 0){
drawClock();
}
}

void drawClock() {
float h = hour();
float alpha = 40;
float hour = 24 - h;
float opacity = 0; //controls darkness of lamp
float hourAlpha = (255/24) * hour ;
if (hour() < 12){ // gets brighter from midnight to noon
opacity = hourAlpha;
} else {
opacity = 255 - hourAlpha; // gets darker from noon to midnight
}
PImage bg = loadImage("bridgeLight.jpg");
float m = minute();
float min = map(m,0,59,0,width);
image(bg,0,0);
fill(0, opacity);
println(hour());
println(hour, "*");
println(hourAlpha);
rect(0,width/3, width, height);
fill(0, 150);
rect(0, width/23, width,100); //second bar
rect(0, width/7, width,100); //min bar

}

 

Written by Comments Off on Waves of light, over a light, reflected off a pool of water. Posted in Assignment-05-Clock