| /home/evankemp/NetBeansProjects/CS1/src/npw/Invention2.java |
1
2
3
4 package npw;
5
6 import java.awt.Color;
7 import painter.SPainter;
8 import shapes.SRectangle;
9
10
11
12 @author
13
14 public class Invention2 {
15
16
17 @param args
18
19 public static void main(String[] args) {
20 int rectangleWidth = 100;
21 int rectangleHeight = 50;
22 int nrOfRec = 500;
23 SPainter me = new SPainter("Invention 2", 1000, 1000);
24 SRectangle rectangle = new SRectangle(rectangleWidth, rectangleHeight);
25 paintTheImage(me, rectangle, nrOfRec, rectangleWidth, rectangleHeight);
26 }
27
28 private static void paintTheImage(SPainter me, SRectangle rectangle, int nrOfRec, int rectangleWidth, int rectangleHeight) {
29 int i = 1;
30 while (i < nrOfRec) {
31 if (i % 2 == 0) {
32 me.move();
33 me.setColor(getColor());
34 me.paint(rectangle);
35 me.setColor(getColor());
36 me.setBrushWidth(getNumber());
37 me.draw(rectangle);
38 } else {
39 me.setColor(getColor());
40 rectangle.shrink(rectangleHeight / 4.0, rectangleWidth / 8.0);
41 me.paint(rectangle);
42 rectangle.expand(rectangleHeight / 4.0, rectangleWidth / 8.0);
43 }
44 i = i + 1;
45 me.tr(Math.random()*90);
46 }
47
48 }
49
50 private static Color getColor() {
51 int rv = (int) (Math.random() * 256);
52 int gv = (int) (Math.random() * 256);
53 int bv = (int) (Math.random() * 256);
54 return new Color(rv, gv, bv);
55 }
56
57 private static int getNumber() {
58 int brushSize = (int) (Math.random() * 5);
59 return brushSize;
60 }
61
62 }
63