Need help for 12-hour PM/AM clock

edited October 2013 in How To...

I'm trying to make a multi-functional background watch as an Android app but I'm having a difficulty figuring out how to make a 12-hour system with PM/AM, meaning that I've no idea how to do so.

Far I've made a 24-hour digital clock (which can be seen below) but I want to make an animated background for my watch at some point so that rect() I've made really gets in the way of doing that, so I need to know of a way to make it so the numbers doesn't keep going over each other endlessly without the use of a rect().

void draw(){
  textAlign(LEFT);

  int day = day();  // Values from 1 - 31
  int month = month();  // Values from 1 - 12
  int year = year();   // 2003, 2004, 2005, etc.
  /*
  String s = String.valueOf(day);
  text(s, 10, 28);

  s = String.valueOf(month);
  text(b, 10, 56);

  s = String.valueOf(year);
  text(s, 10, 84);
  */
  String d = String.valueOf(day);
  String m = String.valueOf(month);
  String y = String.valueOf(year);
  text(d, 25, 25);

  noStroke();
  fill(255);
  rect(150,250,135,25);

  fill(0);
  text(nf(hour(), 2)+":"+nf(minute(), 2)+":"+nf(second(), 2),150,275);
}

Also is there a different between the

  String s = String.valueOf(day);
  s = String.valueOf(month);
  s = String.valueOf(year);

or

  String d = String.valueOf(day);
  String m = String.valueOf(month);
  String y = String.valueOf(year);

Does it take more ram/bits to run my watch with String rather than just s or doesn't it matter at all? I'm aiming for making it the most optimal regarding usage of process power / whatever.

I also want to make a normal clock with lines but I'm finding it a little difficult to place the numbers (1-12) in a round circle, any suggestions how to do that beside just putting them in random places (x,y) until I think it looks decent?

PS. how do I use this forum? Bold doesn't seem to work and it doesn't write the code in the way I write it...

Tagged:

Answers

  • hey fiskefyren,

    here's a simple arc-style clock that I made a while ago for a project:

    Radian[] a;
    int weight = 50;
    
    void setup() 
    {
      size(1400, 900);
      smooth();
      a = new Radian[3];
    
      for (int i=0; i < a.length; i++) {
       a[i] = new Radian(2*weight*i+50, color(random(255),random(255),random(255)), i); 
      }
    
    }
    void draw()
    {
      background(255);
      for (int i=0; i < a.length; i++) {
        a[i].update();
        stroke(a[i].col);
        noFill();
        strokeWeight(weight);
        strokeCap(SQUARE);
        arc(width/2, height/2, a[i].distance, a[i].distance,radians(-90), a[i].finish);
      }
    }
    class Radian {
     int distance, col, type;
     float finish;
    
      Radian (int distance, color col, int type ){
        this.finish = 0;
    
        this.distance = distance;
        this.col = col;
        this.type = type;
     }
     void update (){
       int t = this.type;
       switch (this.type) {
          case 0:
           this.finish = h();
         break;
          case 1:
           this.finish = m();
         break;
          case 2:
           this.finish = s();
         break; 
       }
    
     }
     float h() {
       int h = hour();
       if (h >12) {
         return radians((h-12)*30-90);
       } else {
         return radians((h)*30-90);
       }
       //return radians((h/2)*7-90);
     }
     float m() {
       int m = minute();
       return radians(m*6-90);
     }
     float s() {
       int s = second();
       return radians(s*6-90);
     }
    
    }
    

    Hopefully this gets you started in the right direction.

    as for code formatting, I paste my code in, then click the big 'C' at the top of the textfield. It doesn't seem to do much visually in the editor, it would be nice to get line numbers or something. I think it will code-format it once posted though. As for bold, it looks like it's using Markdown - adding two stars to either side to indicate the bolded word. There's a link to the markdown wikipedia page at the bottom to learn more about what you can use with that.

    Hope this helps! ak

    • Multiple declarations or only one: it doesn't matter, prefer the most readable / meaningful way...
    • Code: there is a button for that, above the edit area.
    • Bold: ditto...
Sign In or Register to comment.