Question: Pls, answer the following java question. With a template below. I am struggling. work with the template //The constants needed in the equations for the
Pls, answer the following java question. With a template below. I am struggling. work with the template

//The constants needed in the equations for the "rose" final float K = 4; //The factor that controls the number of "petals" final float RATE = 0.02; //The change in t each frame. Controls speed and smoothness. final float ROSE_RADIUS = 200; //The radius, in pixels, of the "rose"
//The "state" variables that remember what's happening float t = 0; //The "parameter" t which will slowly change from 0 to 2PI float prevX; //What were x... float prevY; //...and y last time?
void setup() { size(500, 500); //Usual window size background(0); //Use a black background, and... strokeWeight(2); /ice thick lines stroke(255); //that are white //Precalculate the first point (with t=0). This must be done //after the size command because width and height are needed. prevX=width/2+ROSE_RADIUS; prevY=height/2; }
void draw() { //Calculate the new point float x = cos(K*t)*cos(t)*ROSE_RADIUS+width/2; float y = cos(K*t)*sin(t)*ROSE_RADIUS+height/2; line(prevX,prevY,x,y); //draw the next line //Keep all the information needed for next time prevX = x; prevY = y; //Advance t t += RATE; }//draw
labo4 Silver Begin with the solution to the Gold exercise from Lab 4. Use your own solution if you did that exercise. If not, you can use the posted solution from the website (available in the Lab 5 Instructions folder Saturday at 12:01 am). That program drew a "rose" such as the one shown on the right, but it used a white line. In this exercise, modify that program so that will draw each "petal" of the rose using a different random colour. . In each frame, determine whether the newly calculated (x,y) point is farther from the centre than the previous one. Use a boolean variable to store this information. That tells you whether the line is moving away from the middle, or toward it. When should you change the colour? When the line is now moving away from the centre, but it wasn't last time. Use a boolean expression to figure this out. Now you need a few more state variables to keep more information from the last frame. You will need to know how far away the last point was, and whether it was moving toward the centre, or away from it. One of these new state variables must be a boolean variable. To pick a random colour you can use stroke(random(255), random(255), random( 255)); The number of lines of code that you will have to add to the old solution will be quite small. But you will have to read, understand, and modify, some existing code, which is always a big part of computer programming. labo4 Silver Begin with the solution to the Gold exercise from Lab 4. Use your own solution if you did that exercise. If not, you can use the posted solution from the website (available in the Lab 5 Instructions folder Saturday at 12:01 am). That program drew a "rose" such as the one shown on the right, but it used a white line. In this exercise, modify that program so that will draw each "petal" of the rose using a different random colour. . In each frame, determine whether the newly calculated (x,y) point is farther from the centre than the previous one. Use a boolean variable to store this information. That tells you whether the line is moving away from the middle, or toward it. When should you change the colour? When the line is now moving away from the centre, but it wasn't last time. Use a boolean expression to figure this out. Now you need a few more state variables to keep more information from the last frame. You will need to know how far away the last point was, and whether it was moving toward the centre, or away from it. One of these new state variables must be a boolean variable. To pick a random colour you can use stroke(random(255), random(255), random( 255)); The number of lines of code that you will have to add to the old solution will be quite small. But you will have to read, understand, and modify, some existing code, which is always a big part of computer programming
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
