Invention2.java

package npw;

import painter.SPainter;
import shapes.SRectangle;

import java.awt.*;
import java.util.Random;

public class Invention2 {
    public static void main(String[] args) {
        // So Create the Object to Think With it
        SPainter alpha = new SPainter("Invention 2", 600, 600);
        alpha.setBrushWidth(5);
        SRectangle rectangle = new SRectangle(400,300);
        paintTheImage(alpha,rectangle);
    }

    private static void paintTheImage(SPainter painter, SRectangle rectangle) {
        int i = 1;
        while ( i <= 15 ) {
            paintTwoRectangle(painter,rectangle);
            i = i + 1 ;
        }
    }

    private static void paintTwoRectangle(SPainter painter, SRectangle rectangle) {
        Random rgen = new Random();
        double length = rgen.nextInt(200);
        double width = rgen.nextInt(100);
        if (length > 150) {
            painter.setColor(Color.RED);
        } else if (length < 50){
            painter.setColor(Color.BLUE);
        } else painter.setColor(randomColor());
        rectangle.shrink(length,width);
        painter.draw(rectangle);
        rectangle.shrink(-length/7*6,-width/7*6);
        painter.draw(rectangle);
    }

    private static Color randomColor() {
        int rv = (int)(Math.random()*256);
        int gv = (int)(Math.random()*256);
        int bv = (int)(Math.random()*256);
        Color color = new Color(rv,gv,bv);
        return color;
    }
}