Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

malibugranprix2000 Group Title

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 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"); } 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); }

  • one year ago
  • one year ago

  • This Question is Closed
  1. malibugranprix2000 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I am stuck on how to change the background every 15 seconds. Not sure how that is done?

    • one year ago
  2. malibugranprix2000 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Here is the link to what this might look like, it does not have to be exactly like this. http://evc-cit.info/cit020/clock_applet/index.html

    • one year ago
  3. Daire Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Im 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.

    • one year ago
  4. malibugranprix2000 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Oh I am doing this in processing.

    • one year ago
  5. Daire Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Ah 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.

    • one year ago
  6. malibugranprix2000 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    wait 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.

    • one year ago
  7. Daire Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    I used quarter for this part of the solution: "Change the background color of the sketch depending upon which quarter-minute it is: 0-14, 15-29, 30-44, 45-59." 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.

    • one year ago
  8. malibugranprix2000 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ok, thanks. I am going to try figuring this out.

    • one year ago
  9. Daire Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    No problem, good luck with the solution!

    • one year ago
  10. malibugranprix2000 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @Daire like you put so on does that go on until 15?

    • one year ago
  11. malibugranprix2000 Group Title
    Best Response
    You've already chosen the best response.
    Medals 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

    • one year ago
  12. Daire Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    No, 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.

    • one year ago
  13. malibugranprix2000 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Ok I took out the quarter 4. I am realizing that it is still not changing.

    • one year ago
  14. malibugranprix2000 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Is there an example on how to put the changing every 15 seconds part?

    • one year ago
  15. Daire Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    How 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); } }

    • one year ago
  16. malibugranprix2000 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @Daire your setup worked it changes, thanks.

    • one year ago
  17. Daire Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Excellent, glad I could help. Did you find a solution for the triangle and rectangle moving?

    • one year ago
    • Attachments:

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.