Invention2.java
1    package npw;
2    
3    import painter.SPainter;
4    import shapes.SSquare;
5    
6    import java.awt.*;
7    import java.util.Random;
8    
9    public class Invention2 {
10   
11       public static void main(String[] args){
12   
13           SPainter painter = new SPainter("Nondeterministic Invention", 600, 600);
14           SSquare square;
15   
16           Random randomSide = new Random();
17   
18   
19   
20           for (int i = 0; i < 500; i++) {
21   
22               //Creates three random objects for RGB values
23               Random randomR = new Random();
24               Random randomG = new Random();
25               Random randomB = new Random();
26   
27               //sets RGB variables to the random objects created
28               int r = randomR.nextInt(255);
29               int g = randomG.nextInt(255);
30               int b = randomB.nextInt(255);
31   
32               //While loop runs until color is not completely black or white
33               while (true) {
34                   //If the color created is black, then new RGB values will be generated
35                   if (r == 255 && g == 255 && b == 255) {
36                       r = randomR.nextInt(255);
37                       g = randomG.nextInt(255);
38                       b = randomB.nextInt(255);
39                   }
40                   //If the color created is white, the new RGB values will be generated
41                   if (r == 0 && g == 0 && b == 0) {
42                       r = randomR.nextInt(255);
43                       g = randomG.nextInt(255);
44                       b = randomB.nextInt(255);
45                   }
46                   // Any other color will break out of the color loop
47                   else { break; }
48               }
49   
50               //New color object is created to create a custom color from random RGB values
51               Color color = new Color(r, g, b);
52   
53               square = new SSquare(randomSide.nextInt(50));
54               painter.move();
55               painter.setColor(color);
56               painter.draw(square);
57           }
58   
59       }
60   
61   }
62