Loading...
Logo
Processing Forum
Hey guys.

I'm making a clock in the form of a "loading bar" using Processing.

- It's my goal to have the bar LOAD from 12 o clock in the night until 12 o clock in the midday.

- And to have it LOAD BACK (unload) from 12 o clock in the midday until 12 o clock in the night.

..........

Right now I'm having a lot of trouble to make the bar LOAD BACK after it hits 12 o clock in the midday.

Does anyone know the proper code to make it work?

This is my code:

float Time = 0;
float Check = 600;
int Sized = 20;
int Count = 0;

void setup(){
  colorMode(RGB, 720);
  size ( 800,400);
  background(0);
  noStroke();
  smooth(); 
}

void draw() {
 
  float s = second();
  float m = minute()*60;
  float h = hour()*3600;
 
  Time = (m+s+h)*0.01388889;
 
  println (Time);
  println (m+s+h);
 
  if( h >= 12) {
    fill(720);
    rect( 100, 200, 50, Sized);
    fill(200);
    rect( 150, 200, 50, Sized);
    fill(255);
    rect( 200, 200, 50, Sized);
    fill(200);
    rect( 250, 200, 50, Sized);
    fill(255);
    rect( 300, 200, 50, Sized);
    fill(200);
    rect( 350, 200, 50, Sized);
    fill(255);
    rect( 400, 200, 50, Sized);
    fill(200);
    rect( 450, 200, 50, Sized);
    fill(255);
    rect( 500, 200, 50, Sized);
    fill(200);
    rect( 550, 200, 50, Sized);
    fill(255);
    rect( 600, 200, 50, Sized);
    fill(200);
    rect( 650, 200, 50, Sized);
 
    fill(720-(hour()*12),hour()*12,0);
    rect( 100, 200, Time, Sized);
  }
 
  else {
    fill(720);
    rect( 100, 200, 50, Sized);
    fill(360);
    rect( 150, 200, 50, Sized);
    fill(255);
    rect( 200, 200, 50, Sized);
    fill(100);
    rect( 250, 200, 50, Sized);
    fill(255);
    rect( 300, 200, 50, Sized);
    fill(100);
    rect( 350, 200, 50, Sized);
    fill(255);
    rect( 400, 200, 50, Sized);
    fill(100);
    rect( 450, 200, 50, Sized);
    fill(255);
    rect( 500, 200, 50, Sized);
    fill(100);
    rect( 550, 200, 50, Sized);
    fill(255);
    rect( 600, 200, 50, Sized);
    fill(100);
    rect( 650, 200, 50, Sized);
 
    fill(0,0,0);
    rect( 100, 200, Check - Time, Sized);
  }
 

}

Thanks in advance!

Replies(6)

aaaaaargh!

nothing is working!

hahaha I can't help but feel stressed
plz

guys

help me :(

I am on a journey and can therefore only answer in theory...

you got one important if. Good!

you draw x from 100 to Time with
Copy code
  1.   Time = (m+s+h)*0.01388889;
when it's before 12.

now let's see.

You need maxTime as being
Copy code
  1.       maxTime = (59+59+11)*0.01388889;

now when it's after 12, say
Copy code
  1.   Time = (m+s+(h-11))*0.01388889;
  2.   Time = maxTime - Time;

Let me see... best you simulate the behaviour via entering numbers like 16 instead of h and m ..... for testing it.......

you might delete the other thread since it's a duplicate.

Greetings, Chrisir   

[edited]



hmmm

lots of thanks for the help but I really don't know where to write down the exact codes

I'm going to try everything I can to make it work though!

Re: [WatchList] Clock in the form of a "loading bar"

9 months ago   - via EMail-to-forum

Pls put my three lines at the beginning of the long else block

else {
// here



here....................


Copy code
  1. float Time = 0;
  2. //float maxTime = 0;
  3. float Check = 1200;
  4. int Sized = 20;
  5. int Count = 0;
  6. void setup() {
  7.   colorMode(RGB, 720);
  8.   size ( 1200, 400);
  9.   background(0);
  10.   noStroke();
  11.   smooth();
  12. }
  13. void draw() {
  14.   float s = second();
  15.   float m = minute()*60;
  16.   float h = hour()*3600;
  17.   //
  18.   showTime (h, m, s);
  19. }
  20. void showTime (  float h, float m, float s  ) {
  21.   Time = (m+s+h)*0.01388889;
  22.   drawBarBackground();
  23.   if ( h/3600 < 12) {
  24.     // when it's before 12, say
  25.     fill(720-(hour()*12), hour()*12, 0);
  26.     fill(720, 2, 0);
  27.     fill(0, 2, 255);
  28.     rect( 100, 200, Time, Sized);
  29.   }
  30.   else {
  31.     fill(720, 2, 0);
  32.     // fill(0, 0, 0);
  33.     rect( 100, 200, ( Check  ) - Time, Sized);
  34.   }
  35. }
  36. void drawBarBackground() {
  37.   fill(720);
  38.   rect( 100, 200, 50, Sized);
  39.   fill(200);
  40.   rect( 150, 200, 50, Sized);
  41.   fill(255);
  42.   rect( 200, 200, 50, Sized);
  43.   fill(200);
  44.   rect( 250, 200, 50, Sized);
  45.   fill(255);
  46.   rect( 300, 200, 50, Sized);
  47.   fill(200);
  48.   rect( 350, 200, 50, Sized);
  49.   fill(255);
  50.   rect( 400, 200, 50, Sized);
  51.   fill(200);
  52.   rect( 450, 200, 50, Sized);
  53.   fill(255);
  54.   rect( 500, 200, 50, Sized);
  55.   fill(200);
  56.   rect( 550, 200, 50, Sized);
  57.   fill(255);
  58.   rect( 600, 200, 50, Sized);
  59.   fill(200);
  60.   rect( 650, 200, 50, Sized);
  61. }