I need to code the Google Chrome logo but I cannot figure out how to do it. I must create a new project with a tester class (which I already did). I cannot figure out how to make the red, green, and yellow swirl around the blue circle like how the logo looks.
So far I have a code that prints a bullseye, although it has the right colors it does not look right. Additionally, my current code uses instance variables and I would prefer how to do it without them, but I cannot. My code and the image of what it prints is below.
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JComponent;
public class CorporateComponent extends JComponent {
public void paintComponent(Graphics g) {
super.paintComponent(g); // Call parent method for background painting
// Define logo dimensions
int width = getWidth();
int height = getHeight();
int centerX = width / 2;
int centerY = height / 2;
// Draw red circle
g.setColor(new Color(239, 72, 54));
g.fillOval(centerX - 75, centerY - 75, 150, 150);
// Draw yellow circle with smaller radius
g.setColor(new Color(255, 215, 0));
g.fillOval(centerX - 56, centerY - 56, 112, 112);
// Draw green circle with even smaller radius
g.setColor(new Color(76, 187, 23));
g.fillOval(centerX - 42, centerY - 42, 84, 84);
// Draw small blue circle in center
g.setColor(new Color(66, 133, 244));
g.fillOval(centerX - 21, centerY - 21, 42, 42);
}
}
Image:
enter image description here
The image pictures a bullseye made up of the colors green, yellow, red, and blue
user25019520 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.