1 package npw; 2 3 import painter.SPainter; 4 import shapes.SSquare; 5 6 import javax.swing.*; 7 import java.awt.*; 8 import java.awt.geom.Point2D; 9 import java.util.Random; 10 import java.util.Scanner; 11 12 public class Stella { 13 14 public static void paintImage() { 15 16 double largestSide = 700; 17 SPainter painter = new SPainter("Stella", 800, 800); 18 19 int squares = Integer.parseInt(JOptionPane.showInputDialog(null, "Squares")); 20 21 22 23 double distanceBetween = (largestSide / 2) / squares; 24 25 Random r = new Random(); 26 27 28 Color color1 = new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)); 29 Color color2 = new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)); 30 31 Color currentColor = new Color(0, 0, 0); 32 33 boolean clr1 = true; 34 boolean clr2 = false; 35 36 double side = largestSide / 2; 37 38 for (int i = 0; i < squares; i++) { 39 40 if (clr1) { 41 currentColor = color1; 42 clr2 = true; 43 clr1 = false; 44 } else if (clr2) { 45 currentColor = color2; 46 clr1 = true; 47 clr2 = false; 48 } 49 50 System.out.println(side); 51 52 painter.moveTo(new Point2D.Double(400, 400)); 53 SSquare square = new SSquare(side * 2); 54 painter.setColor(currentColor); 55 painter.paint(square); 56 57 side = side - distanceBetween; 58 59 60 } 61 62 } 63 64 public Stella() { paintImage();} 65 66 public static void main(String[] args) { 67 SwingUtilities.invokeLater(new Runnable() { 68 public void run() { 69 new Stella(); 70 } 71 }); 72 } 73 74 } 75