![]() ![]() The radius of the green one should be the geometric mean (the square root of the product) of the radius of the red semicircle and the radius of the magenta semicircle, rounded to the nearest integer. The radius of the magenta semicircle should be 1/4 of height. Test your program.Īdd statements to display the medium (green) and small (magenta) semicircles. Add a statement to the paint method to draw the largest (red) semicircle. x and y are the coordinates of the upper left corner of the rectangle (in this case a square) into which the oval is (logically) inscribed size is the side of the square (and the diameter of the circle) from is the starting point of the arc in degrees (with 0 at the easternmost point of the horizontal diameter), and degrees (a positive number) is the measure of the arc, going counterclockwise. (Recall that the origin of graphics coordinates in Java is at the upper left corner of the content pane with the y-axis pointing down.) Do not plug in fixed numbers from the window’s dimensions.ĭeclare a local variable largeRadius that represents the radius of the largest (red) semicircle and initialize it to 1/4 of width.Ī method call g.fillArc(x, y, size, size, from, degrees) (with all integer arguments) draws a sector of a circle. Initialize them to 1/2 width and 3/4 height (down) of the content pane, respectively. In the paint method, declare local integer variables xCenter and 圜enter that represent the coordinates of the center of the rings. In Rainbow’s constructor, set the window’s background to sk圜olor rather than Color.WHITE. The innermost semicircle has the same color as the background.įollow the instructions below and fill in the blanks in Rainbow.java.Īdd a complete comment header with your name before the class declaration at the top of the file.Īdd to the Rainbow class a declaration of a private final field sk圜olor of the type Color, initialized to Color.CYAN (the color of the sky). The outer ring is red (Color.RED), the middle one is green (Color.GREEN), and the inner ring has the magenta color (Color.MAGENTA). The “rainbow” is made of four overlapping semicircles. I'll probably have more as a I continue to code. How does one set one color for each arc? I tried doing so, and I ended up with the color listed closest the end showing up and overriding the others. My questions: How exactly does fillArc work I understand what goes in the parameter, but what must one do so each arc differs from one another? W.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) arithmetic mean of the widths of the red and magenta rings: so that the width of the middle (green) ring is the Calculate the radius of the innermost (sky-color) semicircle Int mediumRadius = (int) Math.sqrt(smallRadius * largeRadius) G.fillArc(xCenter,圜enter,width,height,0,180) Declare and initialize the radii of the small and medium G.fillArc(xCenter,圜enter,largeRadius,height,0,180) Declare and initialize the radius of the large semicircle: that represent the center of the rainbow rings: Declare and initialize local int variables xCenter, 圜enter Private final Color sk圜olor = Color.CYAN I'll be candid about this it is a homework assignment, but can someone guide me in the right direction and explain to me how some parts of the code are supposed to work? The directions are below the code and the questions. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |