5. Graphics The following is the screen capture of "rotating" a circle around a fixed point. Hint: Ꮎ The one drawn here uses black color to draw a circle rotating in 18 iterations around the center point (100, 100) with radius 40. Write a Java program that can draw this pattern and also the following (a) Change the color to green and draw your own graphic design. (b) Reduce number of iterations to 6 and redraw. (c) Add GUI to control the colors, the number of iterations etc. X Consider a general circle that has rotated an angle 0 from the initial position. We have the x and y axis here and the point O is the point where all the circles are rotating around. The coordinates of the point O is (100, 100). The radius of the circle is 40. Here the angle is the angle formed between the diameter connecting O and the center of the circle C (the red small dot) and the y axis. Compute the coordinates of the center C using this information. Then compute the coordinates of the upper left corner R of the square that encloses the circle. You will use the method g.drawOval (rx, ry, 80, 80) to draw this circle in a for loop. Here rx and ry are the coordinates of the point R. To verify that you have computed correctly, rx = 100 + 40 sin (□). You'll need to compute ry. By the way, you can change the coordinates of O and the value of radius as you wish.
For your convenience, code is provided here:
public void paint(Graphics g){
double theta = 0;
int ry=(int)(150 + 40*Math.sin(theta)), rx=(int)(150 + 40*Math.cos(theta));
int diameter=80;
Calendar c = Calendar.getInstance();
String s;
super.paint(g);
//setBackground(java.awt.Color.blue);
//if(start){
//s = "The start time is: " + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND);
//g.drawString( s, 300, 300);
g.setColor(nowcolor);
//g.drawOval(rx, ry, diameter, diameter);
for(int i = 0; i < iterations; ++i){
//g.setColor(java.awt.Color.lightGray);
g.drawOval(rx, ry, diameter, diameter);
theta += (Math.PI/180)*(360/iterations);
ry = (int)(150 + 40*Math.sin(theta));
rx = (int)(150 + 40*Math.cos(theta));
//g.setColor(java.awt.Color.red);
//g.drawOval(rx, ry, diameter, diameter);
/*try {
Thread.sleep(100);
} catch (InterruptedException e) {
g.drawString("sleep exception", 20, 20);
}*/
}
/*c = Calendar.getInstance();
s = "The stop time is: " + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND);
g.drawString(s, 300, 325);*/
//} }
![2D Graphics
5. Graphics
The following is the screen capture of "rotating" a circle around a fixed point.
Hint:
y
Ꮎ
The one drawn here uses black color to draw a
circle rotating in 18 iterations around the center
point (100, 100) with radius 40.
Write a Java program that can draw this pattern
and also the following
(a) Change the color to green and draw your
own graphic design.
(b) Reduce number of iterations to 6 and
redraw.
(c) Add GUI to control the colors, the number
of iterations etc.
X
X
Consider a general circle that has rotated an angle 0 from the initial position. We have the x and y axis here and
the point O is the point where all the circles are rotating around. The coordinates of the point O is (100, 100).
The radius of the circle is 40. Here the angle 0 is the angle formed between the diameter connecting O and the
center of the circle C (the red small dot) and the y axis.
Compute the coordinates of the center C using this information. Then compute the coordinates of the
upper left corner R of the square that encloses the circle. You will use the method g.drawOval (rx, ry,
80, 80) to draw this circle in a for loop. Here rx and ry are the coordinates of the point R. To verify that
you have computed correctly, rx = 100 + 40 sin (). You'll need to compute ry. By the way, you can
change the coordinates of O and the value of radius as you wish.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd230794e-e523-4ec2-92f4-d9c51a06a3bf%2Ffef31d97-d11a-40d9-8347-f754f0274f67%2Fp3i3gy_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)