Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
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");
}
I have this almost done, but I am having trouble with this if anybody could help me out. For the last step, the minute indicator needs to change color on even and odd minutes. I don't that is happening and shapes such as the rectangle is suppose to move right I don't understand how to do and the triangle is suppose to expand, which is not happening. So while the background is changing every 15 seconds the shapes are suppose to present while moving and changing colors but that is not happening. I am not sure what I am doing wrong.
 one year ago
 one year ago
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"); } I have this almost done, but I am having trouble with this if anybody could help me out. For the last step, the minute indicator needs to change color on even and odd minutes. I don't that is happening and shapes such as the rectangle is suppose to move right I don't understand how to do and the triangle is suppose to expand, which is not happening. So while the background is changing every 15 seconds the shapes are suppose to present while moving and changing colors but that is not happening. I am not sure what I am doing wrong.
 one year ago
 one year ago

This Question is Closed

malibugranprix2000Best ResponseYou've already chosen the best response.0
Here is my work; void setup() { size(400, 400); smooth(); } void draw() { int quarter = second()/15; if (quarter == 0) { background(237, 170, 171); } else if (quarter == 1) { background(197, 160, 240); } else if (quarter == 2) { background(147, 245, 146); } else if (quarter == 3) { int x = second(); int n = 27; if (x % 2 == 0) { fill(247, 5, 41); triangle(200, 200, 180, 220, 220, 220); } else if (x % 2 == 1) { fill(29, 37, 224); rect(20, 20, 60, 60); } } }
 one year ago

malibugranprix2000Best ResponseYou've already chosen the best response.0
@Daire here it is my question to what you were trying to ask.
 one year ago

DaireBest ResponseYou've already chosen the best response.1
Hi @malibugranprix2000, Your solution is more or less correct, but the structure of your program is wrong. Your 'if' statements controlling the background colour are meshed together with the code controlling the shapes when they should be separate. The structure of an 'if' statement is "if (<condition>) {<code to run>} else if (<condition>) {<code to run>}" Have a look at this if you are unsure: http://www.homeandlearn.co.uk/java/java_if_statements.html Here is how you should end the 'if' statements: else if (quarter == 3) { background(100,100,100); }  int x = second(); int n = 27; if (x % 2 == 0) { fill(247, 5, 41); triangle(200, 200, 180, 220, 220, 220); } else if (x % 2 == 1) { fill(29, 37, 224); rect(20, 20, 60, 60); } } I added the dashed line to indicate where you stop the background colour code and start the object code but you should leave this out of the actual code. The last part is not 100% but you have the right idea. Try to separate the code that handles the second object and the minute object. Have you learned about creating methods/functions? They're very useful for structuring your code. You're on the right track. Keep it up!
 one year ago

malibugranprix2000Best ResponseYou've already chosen the best response.0
@Daire I think so, not sure. But what do you mean?
 one year ago

DaireBest ResponseYou've already chosen the best response.1
You need to focus on what your code actually does on each line and how the program flows. I'll explain what you have here. int x = second(); int n = 27; if (x % 2 == 0) { fill(247, 5, 41); triangle(200, 200, 180, 220, 220, 220); } else if (x % 2 == 1) { fill(29, 37, 224); rect(20, 20, 60, 60); } } int x = second(); This gives the variable x the value of second() int n = 27; Gives the variable n the value 27 (not sure why that's here, it isn't used) if (x % 2 == 0) { fill(247, 5, 41); triangle(200, 200, 180, 220, 220, 220); } Checks if the value of x is an even number. If it is even, draw a triangle with the fill colour. else if (x % 2 == 1) { fill(29, 37, 224); rect(20, 20, 60, 60); } Checks if the value of x is an odd number. If it is odd, draws a rectangle with the fill colour. So the flow of this code goes like this: Get the current second Draw a (red?) triangle if the second is even Draw a (blue?) rectangle if the second is odd What you want it do do is: Get the current minute Change fill if minute is even Change fill if minute is odd Then draw shape representing minute Then draw shape representing second A few hints: The colour of the shape will be the colour of the last 'fill()' you used. To make an object move you substitute the coordinates with the second()/minute() functions e.g 'rect(second(), 0, 50,50);' will move the rectangle xcoordinate every second. I hope this helps.
 one year ago

malibugranprix2000Best ResponseYou've already chosen the best response.0
@Daire I am still having trouble with making the square move
 one year ago

DaireBest ResponseYou've already chosen the best response.1
Can you post what code you have so far?
 one year ago

malibugranprix2000Best ResponseYou've already chosen the best response.0
@Daire void setup() { size(400, 400); smooth(); } void draw() { int s = second(); int m = minute(); int quarter = second()/15; if (quarter == 0) { background(237, 170, 171); } else if (quarter == 1) { background(197, 160, 240); } else if (quarter == 2) { background(147, 245, 146); } else if (quarter == 3) { background(219, 211, 135); } { int n = 27; if (n % 2 == 0) { println("n is even"); } else { println("n is odd"); } fill(247, 5, 41); triangle(200, 200, 180, 220, 220, 220); triangle(200, s, 180, 220, 220, 220); } { fill(29, 37, 224); rect(20, 20, 60, 60); rect(m, 20, 60, 60); } }
 one year ago

malibugranprix2000Best ResponseYou've already chosen the best response.0
This is what I have I noticed the triangle is moving down which is good but it needs to change color and the square is not moving also.
 one year ago

malibugranprix2000Best ResponseYou've already chosen the best response.0
i forgot to post this, it might help.This is just a hint what it might look like, http://evccit.info/cit020/clock_applet/index.html
 one year ago

DaireBest ResponseYou've already chosen the best response.1
Hey @malibugranprix2000 This looks good, you're almost done. There's just two minor changes you need to make. int n = 27; if (n % 2 == 0) { println("n is even"); } else { println("n is odd"); } fill(247, 5, 41); triangle(200, 200, 180, 220, 220, 220); triangle(200, s, 180, 220, 220, 220); This code to control the triangle is a little off. The line 'int n = 27;' needs to be removed. What you have done is assigned the number 27 to 'n' which does not change throughout the program execution. Since you want to change the colour every minute you use the value 'm' which you assigned earlier in the code. So the 'if' statement will be 'if (m % 2 == 0)' Also, what you want the 'if' statements to change is the fill colour of the triangle. But what you have is a print statement that prints some text to the console. So the 'if' statements will look like this: if (m % 2 == 0) { fill(10,20,30); } else { fill(50,60,100); } triangle(200, s, 180, 220, 220, 220); You only need one triangle declaration since you're only drawing one triangle. And finally if you look closely you'll notice that your rectangle is moving correctly, but it'll only move about one pixel per minute so it'll be hard to notice. You can increase the amount it moves by multiplying or adding to the 'm' variable when declaring the rectangle. e.g 'rect((m*10), 20, 60, 60);' So if the current minute is 5 the xcoordinate for the rectangle will be 50 (5*10=50), and the next minute it will jump to 60 instead of going from 5 to 6. I hope this clarifies it for you.
 one year ago

malibugranprix2000Best ResponseYou've already chosen the best response.0
Thanks again Daire, this did clarify.
 one year ago

DaireBest ResponseYou've already chosen the best response.1
No problem, glad I could help.
 one year ago
See more questions >>>
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.