I am doing an independent study at my highschool, and I am struggling to finish an assignment. I am meant to draw certain grids of concentric circles in the drawing panel. The circles, when surrounded by a diamond make the diamond appear bent. Here is the code:
import java.awt.*;
public class Illusion {
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel (500, 400);
panel.setBackground(Color.LIGHT_GRAY);
Graphics g = panel.getGraphics();
drawBasic(g, 0, 0, 3, 90);
drawBasic(g, 120, 10, 3, 90);
drawBasic(g, 250, 50, 5, 90);
drawGrid(g, 10, 120, 10, 100, 2);
drawGrid(g, 350, 20, 5, 40, 3);
drawGrid(g, 240, 160, 5, 50, 4);
}
public static void drawBasic(Graphics g, int x, int y,
int circles, int size) {
int gap=size/(2*circles);
g.setColor(Color.ORANGE);
g.fillOval(x, y, size, size);
g.setColor(Color.BLACK);
for (int i=0; i<circles; i++) {
g.drawOval(x+(i*gap), y+(i*gap), size-(2*i*gap), size-(2*i*gap));
}
Polygon diamond = new Polygon();
diamond.addPoint(x+(size/2), y);
diamond.addPoint(x, y+(size/2));
diamond.addPoint(x+(size/2), y+size);
diamond.addPoint(x+size, y+(size/2));
g.drawPolygon(diamond);
}
public static void drawGrid(Graphics g, int x, int y, int circles, int size, int rows){
g.setColor(Color.BLUE);
g.fillRect(x, y, size*rows, size*rows);
g.setColor(Color.ORANGE);
g.drawRect(x, y, size*rows, size*rows);
for(int i=0; i<rows; i++) {
drawBasic(g, x+(i*size), y, circles, size);
}
}
}
I need these grids to complete, rather than just drawing the first row. Currently I am only 3 chapters into the books. I have learned concepts like parameters and for loops, but really don't know any concepts that are not already used somewhere in the program.
I know this post is long, and if there are certain things I'm doing wrong let me know. Thanks,
Aaron
Edit: The assignment link is http://www.cs.washington.edu/educati...ork/3/spec.pdf