anonymous
  • anonymous
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"); } 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.
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
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); } } }
anonymous
  • anonymous
@Daire here it is my question to what you were trying to ask.
anonymous
  • anonymous
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 () {} else if () {}" 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!

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
@Daire I think so, not sure. But what do you mean?
anonymous
  • anonymous
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 x-coordinate every second. I hope this helps.
anonymous
  • anonymous
@Daire I am still having trouble with making the square move
anonymous
  • anonymous
Can you post what code you have so far?
anonymous
  • anonymous
@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); } }
anonymous
  • anonymous
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.
anonymous
  • anonymous
i forgot to post this, it might help.This is just a hint what it might look like, http://evc-cit.info/cit020/clock_applet/index.html
anonymous
  • anonymous
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 x-coordinate 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.
anonymous
  • anonymous
Thanks again Daire, this did clarify.
anonymous
  • anonymous
No problem, glad I could help.

Looking for something else?

Not the answer you are looking for? Search for more explanations.