1 /* 2 *Program to paint a blue dot in the context of the Nonrespresentational 3 * Painting World, NPW 4 */ 5 6 package npw; 7 8 import painter.SPainter; 9 import shapes.SCircle; 10 import shapes.SSquare; 11 12 import javax.swing.*; 13 import java.awt.*; 14 import java.util.Scanner; 15 16 17 public class Stella { 18 19 //THE SOLUTION TO THE BLUE DOT PROBLEM 20 21 private void paintTheImage() { 22 SPainter painter = new SPainter("Stella",800,800); 23 SSquare square = new SSquare(700); 24 int nrOfSquares = nrOfSquares("Number of Squares"); 25 double shrinkFactor = square.side()/(nrOfSquares); 26 Color color1 = randomColor1(); 27 Color color2 = randomColor2(); 28 29 for(int i = nrOfSquares; i>0; i=i-1){ 30 if(i%2==0){ 31 painter.setColor(color1); 32 painter.paint(square); 33 square.shrink(shrinkFactor); 34 }else{ 35 painter.setColor(color2); 36 painter.paint(square); 37 square.shrink(shrinkFactor); 38 } 39 } 40 } 41 42 private Color randomColor1(){ 43 int rv = (int) (Math.random()*256); 44 int gv = (int) (Math.random()*256); 45 int bv = (int) (Math.random()*256); 46 return new Color(rv,gv,bv); 47 } 48 private Color randomColor2(){ 49 int rv = (int) (Math.random()*256); 50 int gv = (int) (Math.random()*256); 51 int bv = (int) (Math.random()*256); 52 53 return new Color(rv,gv,bv); 54 } 55 56 57 private static int nrOfSquares(String prompt){ 58 String nss = JOptionPane.showInputDialog(null, prompt+"?"); 59 Scanner scanner = new Scanner(nss); 60 return scanner.nextInt(); 61 } 62 63 //REQUIRED INFRASTRUCTURE 64 65 public Stella() { 66 paintTheImage(); 67 } 68 public static void main (String[] args) { 69 SwingUtilities.invokeLater(new Runnable() { 70 public void run() { 71 new Stella(); 72 } 73 }); 74 } 75 76 }