1 package npw; 2 3 import painter.SPainter; 4 import shapes.SCircle; 5 import shapes.SSquare; 6 7 import java.awt.*; 8 import java.awt.geom.Point2D; 9 import java.util.Random; 10 11 //Program that draws circles in the form of a circle 12 13 public class Invention1 { 14 15 //dimensions of the window 16 static int height = 800; 17 static int width = 800; 18 19 //Main method that calls the drawing command 20 public static void main(String[] args) { 21 22 //creates a SPainter object with the dimensions of the window given 23 SPainter painter = new SPainter("Deterministic Drawing", height, width); 24 25 //calls the command to draws the circles 26 moveDot(painter); 27 28 } 29 30 //Command that moves painter to a different location and paints a dot at the (x, y position) 31 /* 32 * The window is split into 4 quadrants 33 * The program creates a reference circle in the bottom right corner of the screen 34 * Using trigonometry draws circles are placed on the circumference of the reference circle 35 * Using symmetry, the other 3 quadrants are drawn from the one bottom right corner 36 */ 37 public static void moveDot(SPainter painter) { 38 39 //Variables for the reference circle 40 double angle = 0; 41 double radius = 150; 42 double x; 43 double y; 44 45 //Outter For Loop controls how many rings there are on the window 46 for (int j = 0; j < 3; j++) { 47 //Inner for loop controls how many circles are drawn around the reference circle 48 for (int i = 0; i < 500; i++) { 49 50 //The position of the circle that will be drawn around the circumference of the reference circle is found with trigonometry 51 //The (x, y) is offset. With respect to the center of the window rather than the top left corner of the window 52 //If the angle is zero, then the circle will be drawn on in the middle of the bottom right quadrant 53 //Polar Coordinates ->> Cartesian coordinates 54 x = radius * Math.cos(angle) + 150.0; 55 y = radius * Math.sin(angle) + 150.0; 56 57 //Calls the command to draw the circles on the screen at the given (x, y position on the screen) 58 drawDots(painter, x, y); 59 60 //increases the angle of the reference circle 61 angle += 0.5; 62 } 63 //Creates a smaller ring 64 radius = radius - 50; 65 } 66 } 67 68 //Points are with respect to the center of the window instead of top right corner 69 public static Point2D.Double getCoordinates(double x, double y) { 70 71 //Offsets the given x, y coordinates with respect to the center of the window. 72 //If the given x, y is (0, 0) then the circle will be placed at (WIDTH / 2, HEIGHT / 2) 73 x = x + width / 2; 74 y = y + height / 2; 75 76 //Creates a (x, y) point at the given x, y values 77 Point2D.Double point = new Point2D.Double(x , y); 78 79 //returns that (x, y) point in the form of a Point2D.Double 80 return point; 81 } 82 83 //Command that draws the dots on the screen 84 public static void drawDots(SPainter painter, double x, double y) { 85 86 //Creates a dot object with radius 10 87 SCircle dot = new SCircle(10); 88 89 //sets the color to the random color generated 90 painter.setColor(new Color(0, 150, 255)); 91 92 //Creates a (x, y) point to hold the position of the dot 93 Point2D.Double point; 94 95 //variable point is set the function that returns a new reference frame - with respect to the center of the window 96 point = getCoordinates(x, y); 97 //moves the painter to that (x, y) position 98 painter.moveTo(point); 99 //draws a dot at that (x, y) position 100 painter.draw(dot); 101 102 //Creates a dot in the 3rd quadrant of the window 103 point = getCoordinates(-x, y); 104 painter.moveTo(point); 105 painter.draw(dot); 106 107 //Creates a dot in the first quadrant of the window 108 point = getCoordinates(x, -y); 109 painter.moveTo(point); 110 painter.draw(dot); 111 112 //Creates a dot in the second quadrant of the window 113 point = getCoordinates(-x, -y); 114 painter.moveTo(point); 115 painter.draw(dot); 116 117 } 118 119 } 120