1 package npw; 2 3 import painter.SPainter; 4 import shapes.SCircle; 5 import shapes.SSquare; 6 7 import javax.swing.*; 8 import java.awt.*; 9 import java.util.Random; 10 import java.util.Scanner; 11 12 public class Invention1 { 13 private void paintTheImage(){ 14 SSquare square = new SSquare(750); 15 SCircle circle = new SCircle(375); 16 SPainter painter = new SPainter("Canvas Thing", 1000,1000); 17 int i = 0; 18 while (i <= 50){ 19 if (i % 2 == 0) { 20 painter.setColor(Color.GREEN); 21 painter.paint(circle); 22 circle = new SCircle(circle.radius() * .90); 23 square = new SSquare((square.perimeter() / 4) * 0.9); 24 i = i + 1; 25 } 26 else { 27 painter.setColor(Color.YELLOW); 28 painter.paint(square); 29 circle = new SCircle(circle.radius() * .90); 30 square = new SSquare((square.perimeter() / 4) * 0.9); 31 i = i + 1; 32 33 } 34 35 } 36 } 37 38 private static Color randomColor() { 39 Random rgen = new Random(); 40 int r = rgen.nextInt(256); 41 int g = rgen.nextInt(256); 42 int b = rgen.nextInt(256); 43 return new Color(r, g, b); 44 } 45 public Invention1() { paintTheImage(); 46 } 47 public static void main(String[] args) { 48 SwingUtilities.invokeLater(new Runnable() { 49 public void run() { 50 new Invention1(); 51 } 52 }); 53 } 54 } 55 56 57 58