Hello, I just started getting into learning Java. I wanted to learn how to create graphics with a compiler. I was suggested to start with a large circle that has multiple smaller circles inside of it centered in one another. I started looking across the internet until I came across a pretty simple looking one, so I thought I would give it a try. Here is what I'm talking about, and what I've been working on for practice:
http://www.daube.ch/docu/graphics/moiree_5.gifHere is the code I came up with for this:
CODE
import java.awt.*;
public class BullsEye {
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(500, 500);
panel.setBackground(Color.WHITE);
Graphics g = panel.getGraphics();
g.setColor(Color.BLACK);
g.drawOval(230, 240, 20, 20);
g.drawOval(220, 230, 40, 40);
g.drawOval(210, 220, 60, 60);
g.drawOval(200, 210, 80, 80);
g.drawOval(190, 200, 100, 100);
g.drawOval(180, 190, 120, 120);
g.drawOval(170, 180, 140, 140);
g.drawOval(160, 170, 160, 160);
g.drawOval(150, 160, 180, 180);
g.drawOval(140, 150, 200, 200);
}
}
Is it possible to use for loops in a code like this to reduce some lines? In my quick code above, the x-coordinates are decrementing by 10 with each line, the y-coordinates are also decrementing by 10 with each line (but they begin with a y-coordinate that doesn't match the first x-coordinate of the first inside circle). In contrast, the width is incrementing by 20 on each line and the height is also incrementing by 20 on each line. I was wondering if someone could modify my code to use a for loop for the circle patterns to reduce some lines and explain to me how you did it? I'm not quite sure how to do for loops with graphics. Thanks in advance.
This post has been edited by CerebralAssassin: 9 Jul, 2007 - 02:12 PM