Creato progetto grafica, sistemato shape

This commit is contained in:
2023-05-15 18:38:10 +02:00
parent 7d0cbb0d02
commit 50f648d037
16 changed files with 2074 additions and 120 deletions

View File

@ -0,0 +1,47 @@
package shape;
import java.util.ArrayList;
import java.util.Random;
import java.awt.Graphics2D;
public class Geometria {
private ArrayList<Shape> elementi;
public Geometria() {
elementi = new ArrayList<>();
}
public void riempiACaso(int size) {
Random r = new Random();
for(int i = 0; i < size; i++) {
int s = r.nextInt(3);
double x = r.nextDouble()*300;
double y = r.nextDouble()*300;
switch(s) {
case 0:
//circle
double raggio = r.nextDouble()*30;
elementi.add(new Circle(x, y, raggio));
break;
case 1:
//square
double lato = r.nextDouble()*40;
elementi.add(new Square(x, y, lato));
break;
case 2:
//triangolo
double base = r.nextDouble()*30;
double altezza = r.nextDouble()*30;
elementi.add(new TriangoloRettangolo(x, y, base, altezza));
break;
}
}
}
public void draw(Graphics2D g2) {
for(Shape s : elementi) s.draw(g2);
}
}