package npw; import painter.SPainter; import shapes.SCircle; import shapes.SRectangle; import shapes.SSquare; import javax.swing.*; import java.awt.*; import java.util.Random; import java.util.Scanner; public class Invention2 { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new Invention2(); } }); } public Invention2(){prep();} private void prep(){ double dx = generator(); double dy = (2.0)*generator(); SPainter brush = new SPainter("invention2", 800, 800); SRectangle rectangle = new SRectangle(dx,dy); paintTheImage(brush, rectangle); } public static double generator(){ Scanner gen = new Scanner(System.in); System.out.println("Input any unit length for width and height"); Double lengthGen = gen.nextDouble(); System.out.println("Selected length = " + lengthGen); return lengthGen; } private void paintTheImage(SPainter brush, SRectangle rectangle) { brush.setBrushWidth(5); double scale = rectangle.diagonal(); while (scale<500.0/*constraint: usually inequality form, sometimes, Boolean*/) { //a set of command you want to loop brush.paint(rectangle); brush.mfd(Math.PI + scale); brush.tr(); //rate of change scale = scale + 1; if ( scale>=Math.sqrt(rectangle.width())){ brush.setColor(randomColor()); brush.setBrushWidth((int)(scale)); //block of code to be excuted if the condition is true } else { brush.setColor(Color.black); } } } private static Color randomColor(){ Random rgen = new Random(); int r = rgen.nextInt(256); int g = rgen.nextInt(256); int b = rgen.nextInt(256); return new Color(r, g, b); } }