A community for students. Sign up today!
Here's the question you clicked on:
 0 viewing
 2 years ago
Can someone help me on this, hints, tips anything. But I am really confused how to get this done.
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 quarterminute it is: 014, 1529, 3044, 4559.
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");
}
This is what I have so far
void setup() {
size(400, 400);
smooth();
}
void draw()
{
background(255, 102, 104)
triangle(200, 200, 180, 220, 220, 220);
rect(20, 20, 60, 60);
}
 2 years ago
Can someone help me on this, hints, tips anything. But I am really confused how to get this done. 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 quarterminute it is: 014, 1529, 3044, 4559. 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"); } This is what I have so far void setup() { size(400, 400); smooth(); } void draw() { background(255, 102, 104) triangle(200, 200, 180, 220, 220, 220); rect(20, 20, 60, 60); }

This Question is Closed

malibugranprix2000
 2 years ago
Best ResponseYou've already chosen the best response.0I am stuck on how to change the background every 15 seconds. Not sure how that is done?

malibugranprix2000
 2 years ago
Best ResponseYou've already chosen the best response.0Here is the link to what this might look like, it does not have to be exactly like this. http://evccit.info/cit020/clock_applet/index.html

Daire
 2 years ago
Best ResponseYou've already chosen the best response.1Im guessing the solution is done in Java? If so it seems you'd need to create a new thread to control when the image is updated. One way of doing this is to extend the Thread class and then call the 'run()' method to compute the new image. In the run() method you'll need to create a loop and call the sleep() method at the end of the loop so that it'll wait for 15 seconds before updating again. For example: public void run() { while (1==1) { ...<Calculate new dimensions >... ...<Update canvas>... sleep(15000); } } Also, you might want to change the 'while(1==1)' to something that'll eventually exit. It's not really good practice to create infinite loops. Hope this helps.

malibugranprix2000
 2 years ago
Best ResponseYou've already chosen the best response.0Oh I am doing this in processing.

Daire
 2 years ago
Best ResponseYou've already chosen the best response.1Ah ok, I'm afraid I don't know anything about Processing. But as a general solution you should be able to substitute the parameters for your shapes with the return value of the minute(), second() methods. So for example, where you have 'rect(20, 20, 60, 60);' you could write 'rect(minute(), 20, 60, 60);' so that if the current minute is '24' the compiler will read it as 'rect(24, 20, 60, 60);' I don't know how Processing handles the timing of the threads so I can't really help you with changing the background every 15 seconds. But maybe have a look at checking which quarter of the minute it is currently and change the background depending on what it is. For example: int quarter = second()/15; //if its the first 15 seconds of the minute it will be '0', the second quarter will be '1' the third quarter will be '2' and fourth quarter will be '3'. if(quarter == 0) { background(255, 102, 104); } else if (quarter == 1) { background(0,0,0); } else if... ..and so on. Hope this makes sense.

malibugranprix2000
 2 years ago
Best ResponseYou've already chosen the best response.0wait why did you put quarter because isn't it suppose to be minute. I am working with minute and seconds. The other thing was rectangle is set to minute and the triangle seconds.

Daire
 2 years ago
Best ResponseYou've already chosen the best response.1I used quarter for this part of the solution: "Change the background color of the sketch depending upon which quarterminute it is: 014, 1529, 3044, 4559." since you were asking about how to change the background colour every 15 seconds. If you divide the current seconds by 15 you will get which quarter of the minute you are in. I'm assuming that Processor will constantly run the draw() method so long as the program is running so it will check every second and change the background only when the second is in the next quarter of the minute i.e every 15 seconds.

malibugranprix2000
 2 years ago
Best ResponseYou've already chosen the best response.0ok, thanks. I am going to try figuring this out.

Daire
 2 years ago
Best ResponseYou've already chosen the best response.1No problem, good luck with the solution!

malibugranprix2000
 2 years ago
Best ResponseYou've already chosen the best response.0@Daire like you put so on does that go on until 15?

malibugranprix2000
 2 years ago
Best ResponseYou've already chosen the best response.0{ if (quarter == 0) { background(255, 102, 104); } else if (quarter == 1) { background(121, 12, 232); }else if (quarter == 2) { background(121, 149, 245); }else if (quarter == 3) background(161, 242, 95); }else if (quarter == 3) { background(192, 206, 181); }else if (quarter == 4); This is how I am doing right now

Daire
 2 years ago
Best ResponseYou've already chosen the best response.1No, it only goes up to 3 since there are only four quarters in a minute (0, 1, 2 and 3). You will also need to define the variable 'quarter' by adding the line 'int quarter = second()/15' before your 'if' statements. So the code will be: { int quarter = second()/15; if (quarter == 0) { background(0,0,0); } else if (quarter == 1) { background(10,10,10); } else if (quarter == 2) { background(50,50,50); } else if (quarter == 3) { background(100,100,100); } } There was a small syntax error in that post btw, where you had your third 'if' statement but I've corrected it here. Hope that clarifies.

malibugranprix2000
 2 years ago
Best ResponseYou've already chosen the best response.0Ok I took out the quarter 4. I am realizing that it is still not changing.

malibugranprix2000
 2 years ago
Best ResponseYou've already chosen the best response.0Is there an example on how to put the changing every 15 seconds part?

Daire
 2 years ago
Best ResponseYou've already chosen the best response.1How are you getting along? I've downloaded Processor and had a little play about with it. I got the background changing every 15 seconds using this: void setup() { size(400, 400); smooth(); } void draw() { int quarter = second()/15; if (quarter == 0) { background(0,0,0); } else if (quarter == 1) { background(255,10,10); } else if (quarter == 2) { background(50,255,50); } else if (quarter == 3) { background(255,255,255); } }

malibugranprix2000
 2 years ago
Best ResponseYou've already chosen the best response.0@Daire your setup worked it changes, thanks.

Daire
 2 years ago
Best ResponseYou've already chosen the best response.1Excellent, glad I could help. Did you find a solution for the triangle and rectangle moving?
Ask your own question
Ask a QuestionFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.