1 package npw; 2 3 import painter.SPainter; 4 import shapes.SSquare; 5 6 import java.awt.*; 7 8 import java.util.Random; 9 10 public class Invention2 { 11 12 public static void main (String [] args) { 13 int squareSide = 600; 14 SPainter painter = new SPainter("Random squares" , 700 , 700); 15 SSquare square = new SSquare(squareSide); 16 17 //Paints the squares 18 paintSquares(painter, square, squareSide); 19 20 } 21 22 private static void paintSquares(SPainter painter, SSquare square, int squareSide) { 23 fourSquares(painter, square, squareSide); 24 painter.mfd(square.side() / 2); 25 painter.mlt(square.side() / 2); 26 square.resetSide(118); 27 28 double i = square.side(); 29 while (i < squareSide + 240) { 30 painter.setColor(randomColor()); 31 painter.paint(square); 32 painter.mrt(square.side()); 33 i = i + square.side(); 34 35 if (i >= squareSide) { 36 for (double x = square.side(); i < squareSide + 240; x = x + square.side()) { 37 painter.setColor(randomColor()); 38 painter.paint(square); 39 painter.mbk(square.side()); 40 } 41 } 42 } 43 } 44 45 //Draws four squares 46 private static void fourSquares(SPainter painter, SSquare square, int squareSide) { 47 int i = 0; 48 int squaresToPaint = 4; 49 while (i < squaresToPaint) { 50 painter.setColor(Color.BLACK); 51 painter.setBrushWidth(3); 52 square.shrink(120); 53 painter.draw(square); 54 i = i + 1; 55 } 56 painter.moveToCenter(); 57 square.resetSide(squareSide); 58 } 59 60 private static Color randomColor() { 61 Random rand = new Random(); 62 int r = rand.nextInt(256); 63 int b = rand.nextInt(256); 64 int g = rand.nextInt(256); 65 return new Color(r, b , g); 66 67 } 68 } 69