Create a window with size 600 x 600. • Draw a circle with radius 25. The center
ID: 3749026 • Letter: C
Question
Create a window with size 600 x 600.
• Draw a circle with radius 25. The center of the circle is 200 pixels away from the center of the window.
• Rotate the circle around the center of the window.
• Declare a global variable named rotationalSpeed to control the speed of rotation. If its value is 1, then the circle rotates 1 degree counterclockwise each time when the draw method is called.
• Implement a method called rotate to rotate a point by a given angle around the origin. Here is the method header:
void rotate(float theta, PVector point)
The method updates the point variable with the new location of the point after rotation.
The PVector class is a predefined class in the Processing library. It is just like the Vector2D class you implemented by yourself except it supports more functions for vectors. You can directly use it in your program.
• Implement a method called convertDegreesToRadians to convert degrees to radians. Here is the method header:
float convertDegreesToRadians(float d)
• Use the rotate method and convertDegreesToRadians method in your program to rotate the circle.
Explanation / Answer
int a = 80; // Create a global variable "a" void setup() { size(640, 360); background(0); stroke(255); noLoop(); } void draw() { // Draw a line using the global variable "a" line(a, 0, a, height); // Create a new variable "a" local to the for() statement for (int a = 120; a < 200; a += 2) { line(a, 0, a, height); } // Create a new variable "a" local to the draw() function int a = 300; // Draw a line using the new local variable "a" line(a, 0, a, height); // Make a call to the custom function drawAnotherLine() drawAnotherLine(); // Make a call to the custom function setYetAnotherLine() drawYetAnotherLine(); } void drawAnotherLine() { // Create a new variable "a" local to this method int a = 320; // Draw a line using the local variable "a" line(a, 0, a, height); } void drawYetAnotherLine() { // Because no new local variable "a" is set, // this line draws using the original global // variable "a", which is set to the value 80. line(a+2, 0, a+2, height); }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.