Coordinates of an Equilateral Triangle
The goal is to tesselate a plane using either equilateral triangles,
squares, or hexagons, determined by an integer read from a file. The side
length is also given by reading an integer from a file. I've done it for
squares, but the triangle has me stumped. I've been trying to use
drawPolygon. I assume the side length will correlate to the distance from
point a to point b to point c, but i really have no clue as to how to find
the coordinates. Any help would be appreciated.
import java.awt.*;
import javax.swing.JPanel;
public class DrawShapes extends JPanel {
private int shape; //user choice of which shape to draw
private int sideLength; //user choice of what length to draw the sides
public DrawShapes(int shapeChoice, int sideChoice) {
shape = shapeChoice;
sideLength = sideChoice;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
switch(shape) {
case 3: //Draws triangles
//int[] x =
//int[] y =
//int[] n =
g.setColor(Color.green);
//g.drawPolygon(x,y,n);
break;
case 4: //Draws squares
g.setColor(Color.blue);
g.drawRect(sideLength*i, sideLength*j, sideLength,
sideLength);
break;
case 6: //Draws hexagons
break;
}
}
}
}
}
No comments:
Post a Comment