|
Author |
Topic: please explain (Read 591 times) |
|
r_gaberz
|
please explain
« on: Jan 9th, 2004, 11:03pm » |
|
// Warning newbie could someone explain this code to me? i can't understand why the bars move! There is no if or while function. everything seems to be static ------------------------------------------- // Seconds Minutes Hours // By mescobosa int LNhour = 18; int LNmin = 11; int LNsec = 4; int Hhour = 120; int Hmin = 60; int Hsec = 20; int Yhour = 0; int Ymin = Hhour; int Ysec = Hhour + Hmin; void setup() { size(200, 200); noStroke(); } void loop() { background(0); int hr = hour(); int min = minute(); int sec = second(); float xposHour = hr * width/23.0; float xposMin = min * width/59.0; float xposSec = sec * width/59.0; fill(255); rect(xposHour - LNhour, Yhour, LNhour, Hhour); rect(xposMin - LNmin, Ymin, LNmin, Hmin); rect(xposSec - LNsec, Ysec, LNsec, Hsec); rect(xposHour/2 - LNhour, Yhour, LNhour, Hhour); rect(xposMin/2 - LNmin, Ymin, LNmin, Hmin); rect(xposSec/2 - LNsec, Ysec, LNsec, Hsec); rect(xposHour/4 - LNhour, Yhour, LNhour, Hhour); rect(xposMin/4 - LNmin, Ymin, LNmin, Hmin); rect(xposSec/4 - LNsec, Ysec, LNsec, Hsec); rect(xposHour/8 - LNhour, Yhour, LNhour, Hhour); rect(xposMin/8 - LNmin, Ymin, LNmin, Hmin); rect(xposSec/8 - LNsec, Ysec, LNsec, Hsec); rect(xposHour/16 - LNhour, Yhour, LNhour, Hhour); rect(xposMin/16 - LNmin, Ymin, LNmin, Hmin); rect(xposSec/16 - LNsec, Ysec, LNsec, Hsec); } ----------------------------------------------------
|
.
|
|
|
arielm
|
Re: please explain
« Reply #1 on: Jan 10th, 2004, 9:36pm » |
|
the answer is blowing in the following 3 lines: Code:int hr = hour(); int min = minute(); int sec = second(); |
| where hour(), minute() and second() are 3 processing predefined functions returning values based on your computer's clock... one receipe that works well when reading pieces of code: - start to read from the top. - stop when something is not clear and try to gather more info about it... so for instance, when you fall on the hour() statement: - it's a function that you don't know. - you can see in the code that this function is not declared anywhere. - then you can go in the "reference" and search for this function (what is does and most importantly: what kind of value it returns...)
|
« Last Edit: Jan 11th, 2004, 12:01am by arielm » |
|
Ariel Malka | www.chronotext.org
|
|
|
fry
|
Re: please explain
« Reply #2 on: Jan 10th, 2004, 11:25pm » |
|
hopefully you don't even have to search in the reference for the function, but can select the function name (just the name, no parens), then right-click and select 'find in reference' and it'll show you the reference directly.
|
|
|
|
|