Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 1677
Number of posts: 4766

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
begnining programming Posted by malibugranprix on 3 Oct 2012 at 1:35 PM
Processing has functions that let you determine the time of day: second(), minute(), and hour(). You will use the minute and second functions to control a sketch with two items in it. Save the sketch with the name time.

Use the minute() function to control the position of one item.
Use the second() function to control the size of the other item.

The position and size changes must be evident. The fill color for the “seconds” indicator must not change.

For example, you might choose a triangle as the indicator for the minute, and move it vertically down the sketch as time progresses. You might choose an ellipse for the second indicator, and make it longer as the seconds progress. None of this requires the use of any conditionals (though if you do want to use conditionals for extra visual effect, feel free). Here are two further specifications which do require conditionals:

Change the background color of the sketch depending upon which quarter-minute it is: 0-14, 15-29, 30-44, 45-59.
Change the fill color of the minute indicator depending upon whether the minute is an even or odd number.

Although you are using the time functions, your sketch does not have to look like a clock. I don’t care if nobody can tell what time it is by looking at your sketch. It can be as representational or as abstract as you like, so be creative!

Here is an example; it is the clock as described above. Yours, of course, will look different.

How do you find out if a number is odd or even? You use the % operator. This gives you the remainder after division. For example, 17 % 3 gives you 2, because 17 divided by 3 is 5 with a remainder of 2.

Here’s the trick: if you divide a number by 2, you get a remainder of zero if the number is even, and a remainder of one if it’s odd. So this code will print the appropriate message:

int n = 27;
if (n % 2 == 0)
{
println("n is even");
}
else
{
println("n is odd");
}

void setup() {
size(400, 400);
smooth();
}

void draw()
{
background(255, 102, 204);

triangle(200, 200, 180, 220, 220, 220);
rect(20, 20, 60, 60);
}
I am stuck on how to change the background every 15 seconds. Not sure how that is done?



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.