1 /* 2 * Program to make some art 3 * It uses at least one while statement in a nontrivial way. 4 * It uses at least one if statement in a nontrivial way. 5 * It features both circles and squares, all created from just one circle and just one square. No rectangles. 6 * It creates the exact same image every time it is run. 7 * There is some chance that the casual observer might find the image interesting! 8 */ 9 10 package npw; 11 12 import painter.SPainter; 13 import shapes.SCircle; 14 import shapes.SSquare; 15 16 import javax.swing.*; 17 import java.awt.*; 18 import java.util.Scanner; 19 20 public class Invention1 { 21 22 private void paintTheImage() { 23 //introductions 24 quickConversing(); 25 //establish a painter and some shapes 26 SPainter chad = new SPainter("Invention1",1300,850); 27 chad.setColor(Color.BLACK); 28 SSquare square = new SSquare(50); 29 SCircle circle = square.circumscribingCircle(); 30 //paint some stuff 31 paintSomeCircles(chad,circle); 32 paintSomeSquares(chad,square); 33 } 34 35 private void paintSomeSquares(SPainter chad, SSquare square) { 36 panelOne(chad,square); 37 panelTwo(chad,square); 38 panelThree(chad,square); 39 panelFour(chad,square); 40 } 41 42 private void panelFour(SPainter chad, SSquare square) { 43 chad.mrt(chad.canvasWidth()/6.0); 44 chad.mbk(chad.canvasHeight()/7.0); 45 int i = 1; 46 while (i <= 5) { 47 chad.paint(square); 48 chad.mbk(square.side()); 49 i = i+1; 50 } 51 chad.mfd(square.side()); 52 chad.mrt(square.side() * 2); 53 int k = 1; 54 while (k <= 5) { 55 chad.paint(square); 56 chad.mrt(square.side()); 57 k = k+1; 58 } 59 chad.moveToCenter(); 60 } 61 62 private void panelThree(SPainter chad, SSquare square) { 63 chad.mlt(chad.canvasWidth()/3.5); 64 chad.mbk(chad.canvasHeight()/7.0); 65 int i = 1; 66 while (i <= 5) { 67 chad.paint(square); 68 chad.mbk(square.side()); 69 i = i+1; 70 } 71 chad.mfd(square.side()); 72 chad.mrt(square.side() * 2); 73 int k = 1; 74 while (k <= 5) { 75 chad.paint(square); 76 chad.mfd(square.side()); 77 k = k+1; 78 } 79 chad.moveToCenter(); 80 } 81 82 private void panelTwo(SPainter chad, SSquare square) { 83 chad.mrt(chad.canvasWidth()/3.5); 84 chad.mfd(chad.canvasHeight()/7.0); 85 int i = 1; 86 while (i <= 5) { 87 chad.paint(square); 88 chad.mfd(square.side()); 89 i = i+1; 90 } 91 chad.mbk(square.side()); 92 chad.mlt(square.side() * 2); 93 int k = 1; 94 while (k <= 5) { 95 chad.paint(square); 96 chad.mbk(square.side()); 97 k = k+1; 98 } 99 chad.moveToCenter(); 100 } 101 102 private void panelOne(SPainter chad, SSquare square) { 103 chad.mlt(chad.canvasWidth()/4.0); 104 chad.mfd(chad.canvasHeight()/7.0); 105 int i = 1; 106 while (i <= 5) { 107 chad.paint(square); 108 chad.mfd(square.side()); 109 i = i+1; 110 } 111 chad.moveToCenter(); 112 } 113 114 private void paintSomeCircles(SPainter chad, SCircle circle) { 115 //get into position for bisecting line 116 chad.mlt(chad.canvasWidth()/2.0); 117 //painting 118 int i = 1; 119 while (i<chad.canvasWidth()/25) { 120 if (chad.paintBrushColor() == Color.BLACK) { 121 chad.setColor(Color.WHITE); 122 } else { 123 chad.setColor(Color.BLACK); 124 } 125 chad.mrt(25); 126 chad.paint(circle); 127 i = i + 1; 128 } 129 //the other line 130 chad.moveToCenter(); 131 chad.mfd(chad.canvasHeight()/2.0); 132 133 //painting 134 int k = 1; 135 while (k < chad.canvasHeight()/25) { 136 if (chad.paintBrushColor() == Color.BLACK) { 137 chad.setColor(Color.WHITE); 138 } else { 139 chad.setColor(Color.BLACK); 140 } 141 chad.mbk(25); 142 chad.paint(circle); 143 k = k + 1; 144 } 145 //make invariant 146 chad.moveToCenter(); 147 148 } 149 150 private void quickConversing() { 151 String nss = JOptionPane.showInputDialog(null,"What is your favorite color"); 152 Scanner scanner = new Scanner(nss); 153 String response = scanner.next(); 154 JOptionPane.showMessageDialog(null,response + 155 ". Hmm, odd choice, but not bad I suppose. \nOh well here is some art"); 156 } 157 158 public Invention1() { 159 paintTheImage(); 160 } 161 public static void main(String[] args) { 162 SwingUtilities.invokeLater(new Runnable() { 163 @Override 164 public void run() { 165 new Invention1(); 166 } 167 }); 168 } 169 } 170