1 package npw; 2 3 import painter.SPainter; 4 import shapes.SRectangle; 5 6 import javax.swing.*; 7 import java.awt.*; 8 import java.util.Random; 9 10 public class Invention2 { 11 private void paintTheImage(){ 12 int length = 900; 13 int Height = 500; 14 SRectangle rectangle = new SRectangle(Height,length); 15 SPainter painter = new SPainter("Canvas Thing", 1000,1000); 16 Random rgen = new Random(); 17 int rn = rgen.nextInt(3); 18 while (rn <= 80){ 19 20 if ( rn % 2 == 0 ) { 21 painter.setColor(randomColor()); 22 painter.paint(rectangle); 23 rectangle = new SRectangle( rectangle.height() * .90 , rectangle.width() * .90); 24 int rnadd = rgen.nextInt(3); 25 rn = rn + rnadd; 26 } 27 else { 28 int rn2 = rgen.nextInt(10); 29 if (rn2 < 5) { 30 painter.setColor(randomColor()); 31 painter.draw(rectangle); 32 rectangle = new SRectangle( rectangle.width() * .90 , rectangle.width() * .9); 33 int rnadd = rgen.nextInt(3); 34 rn = rn + rnadd; 35 } 36 else { 37 painter.setColor(randomColor()); 38 painter.paint(rectangle); 39 rectangle = new SRectangle(rectangle.height() * .90, rectangle.width() * .90); 40 int rnadd = rgen.nextInt(3); 41 rn = rn + rnadd; 42 } 43 } 44 } 45 46 47 } 48 49 private static Color randomColor() { 50 Random rgen = new Random(); 51 int r = rgen.nextInt(256); 52 int g = rgen.nextInt(256); 53 int b = rgen.nextInt(256); 54 return new Color(r, g, b); 55 } 56 public Invention2() { paintTheImage(); 57 } 58 public static void main(String[] args) { 59 SwingUtilities.invokeLater(new Runnable() { 60 public void run() { 61 new Invention2(); 62 } 63 }); 64 } 65 }