My program draw 10 polygon triangles in random sizes (width and height). The coordinate (points) of the polygon were generated using Random generator = new Random()
. Since the points of the triangle and the width and height were randomly generated, how can I control the number of sizes drawn? e.g. there are 10 polygon in total, but I wanted to limit the number of different sizes e.g. only 2 or 4 different sizes.
for(int i = 0; i < 10; i++) {
double xWidth = generator.nextDouble() * 50.0 + 20.0; // range width of triangle
double yHeight = generator.nextDouble() * 50.0 + 20.0; // range height of triangle
xCoord[0] = generator.nextInt(300);
yCoord[0] = generator.nextInt(300);
xCoord[1] = (int) (xCoord[0] - xWidth);
xCoord[2] = (int) (xCoord[1] + (xWidth/2));
yCoord[1] = yCoord[0];
yCoord[2] = (int) (yCoord[1] - yHeight);
triangles.add( new Polygon(xCoord,yCoord, 3));
}