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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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.
Transcribed Image Text: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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education