How should I randomize the x/y values for specific points, as well as the color of the polygons they create, in Java? I have code I'm trying to use to create this effect, 500 times in a row, with 500 different triangles, randomizing every triangle in the same way (this is the code I'm requesting help with):
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Canvas;
import javax.swing.JFrame;
import java.awt.Polygon;
import java.util.Random;
public final class CRassignment34 extends Canvas
{
private static final long serialVersionUID=99L;
public static final void main (String[] args)
{
final JFrame win=new JFrame("500 randomly-selected triangles (a trainwreck indeed)");
win.setSize(1024,768);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.add(new CRlab34());
win.setVisible(true);
}
public final void paint (Graphics g)
{
for (int i=0;i<500;i++)
{
final Polygon tri=new Polygon();
final Random r=new Random();
tri.addPoint(x,y);
tri.addPoint(x,y);
tri.addPoint(x,y);
g.setColor(colorRand());
g.fillPolygon(tri);
}
}
public final void colorRand(Color c)
{
}
}