dimanche 7 octobre 2018

Draw polygon inside the frame dynamically

I would like to remove Randomize values and make it dynamic to avoid showing my polygon outside of the given frame size which is also (540,380).

protected Polygon polygonData() {
Random random = new Random(System.currentTimeMillis());
int xAxis = random.nextInt(540);
int yAxis = random.nextInt(380);

Polygon data = new Polygon();
data.addPoint(5 + xAxis, 15 + yAxis);
data.addPoint(48 + xAxis, 18 + yAxis);
data.addPoint(43 + xAxis, 33 + yAxis);
data.addPoint(21 + xAxis, 51 + yAxis);

//In this case if i have x as 540 and y as 380 randomly, my polygon will go outside of the frame. How to limit dynamically?
return data;}




Aucun commentaire:

Enregistrer un commentaire