Advertisement
Guest User

RandomCircles

a guest
Oct 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. public class RandomCircles extends Application
  2. {
  3. /**
  4. * Returns circles of random shape, color, and size
  5. */
  6. public void start(Stage primaryStage)
  7. {
  8. Group root = new Group();
  9. double max = -1;
  10. Circle largest = null;
  11.  
  12. //create the 30 random circles
  13. for (int circle = 0; circle <= 30; circle++)
  14. {
  15. Random gen = new Random();
  16. int x = gen.nextInt(600);
  17. int y = gen.nextInt(400);
  18. int radius = gen.nextInt(66) + 10; //z is the radius
  19.  
  20. int red = gen.nextInt(256);
  21. int blue = gen.nextInt(256);
  22. int green = gen.nextInt(256);
  23. //256 so that the range is from 0-255, the color range
  24.  
  25.  
  26.  
  27.  
  28.  
  29. Circle circle1 = new Circle(x, y, radius);
  30. circle1.setFill(Color.WHITE);
  31. circle1.setStroke(Color.rgb(red, green, blue));
  32. circle1.setStrokeWidth(3);
  33. root.getChildren().add(circle1);
  34.  
  35. if (circle1.getRadius() > max)
  36. {
  37. largest = circle1;
  38. max = circle1.getRadius();
  39. }
  40. }
  41. largest.setFill(Color.color(1.0, 0, 0, 0.3));
  42. //0.3 represents the desired opacity of the largest circle
  43.  
  44. Scene scene = new Scene(root, 600, 400, Color.WHITE);
  45. primaryStage.setTitle("Random Circles");
  46. primaryStage.setScene(scene);
  47. primaryStage.show();
  48. }
  49.  
  50. public double getRadius()
  51. {
  52. double radius = 0;
  53. return radius;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement