Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RandomCircles extends Application
- {
- /**
- * Returns circles of random shape, color, and size
- */
- public void start(Stage primaryStage)
- {
- Group root = new Group();
- double max = -1;
- Circle largest = null;
- //create the 30 random circles
- for (int circle = 0; circle <= 30; circle++)
- {
- Random gen = new Random();
- int x = gen.nextInt(600);
- int y = gen.nextInt(400);
- int radius = gen.nextInt(66) + 10; //z is the radius
- int red = gen.nextInt(256);
- int blue = gen.nextInt(256);
- int green = gen.nextInt(256);
- //256 so that the range is from 0-255, the color range
- Circle circle1 = new Circle(x, y, radius);
- circle1.setFill(Color.WHITE);
- circle1.setStroke(Color.rgb(red, green, blue));
- circle1.setStrokeWidth(3);
- root.getChildren().add(circle1);
- if (circle1.getRadius() > max)
- {
- largest = circle1;
- max = circle1.getRadius();
- }
- }
- largest.setFill(Color.color(1.0, 0, 0, 0.3));
- //0.3 represents the desired opacity of the largest circle
- Scene scene = new Scene(root, 600, 400, Color.WHITE);
- primaryStage.setTitle("Random Circles");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- public double getRadius()
- {
- double radius = 0;
- return radius;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement