Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Pls use the java language to solve this Exercise 2. Create an active Processing program that visualizes the remainder (modulo or mod) operator (%). You
Pls use the java language to solve this
Exercise 2. Create an active Processing program that visualizes the remainder (modulo or mod) operator (%). You will do this by making a block that follows the mouse, but the block's size will be the remainder when the x coordinate is divided by 100. Specifically: a. Create the setup and draw blocks, and resize the canvas to 500x500 in the setup block. b. Create the following global integer constants (use final" to declare them) and set them to reasonable greyscale values: BG_COLOR, BOX COLOR c. In the draw block, create the following local variables and set them to the current mouse coordinates: boxX (set to mouseX), boxy (set to mousey) d. Create a local variable boxSize and set it temporarily to size 30. e. Use the rect command to draw the box using boxx, boxy, and boxSize. Don't forget to set the fill color. f. Run your program and make sure that the box follows the mouse around. Notice that the box touches the mouse at the top left corner. g. Next, make the box centered on the mouse. Offset boxX and boxy by half the size of the box. That is, subtract boxSize/2 from mousex and from mousey when setting boxX and boxy. This will make the box centered on the mouse. Be sure to use the boxSize variable and not literal numbers. h. Run your program it should now follow the mouse but be centered on the mouse. i. Now, to visualize mod, set the box size to the remainder when you divide the mousex coordinate by 100. Remember that you can get the remainder by using the operator. The size of the box will now change to values from 0 to 99. j. Run your program. You should now see what the remainder looks like as you move the mouse from left to right across the x axis it gets larger until it reaches its maximum size, then resets to size 0, and repeats! k. Finally, after calculating boxSize, but before using it to calculate boxX and boxy, make sure that the size is never less than 10. Use either the min or the max function to do thisStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started