// DrawingWorld.java import draw.Posn; import draw.World; import draw.Color; import draw.Red; import draw.White; import draw.Green; import draw.Blue; /* ; ; ; ; ;;;;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;;; ; ;; ; ;;;; ; ; ; ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;; ; ; ;;;;; ; ;;; ; ;; ; ; ; */ // to represent a blob on the canvas class Blob { Posn center; int radius; Blob(Posn center, int radius) { this.center = center; this.radius = radius; } // draw this blob in the given World boolean draw(World w) { return w.drawDisk(this.center, this.radius, new Red()); } // produce a blob with the center moved by the given distance; Blob move(int dx, int dy){ return new Blob(new Posn(this.center.x + dx, this.center.y + dy), this.radius); } // determine whether this blob is the same as than given blob boolean same(Blob b){ return this.center.x == b.center.x && this.center.y == b.center.y && this.radius == b.radius; } } /* ; ; ; ; ;;;;;; ; ; ; ; ; ; ; ; ; ; ; ;;; ; ;; ;; ; ;; ; ;;; ;;; ; ;;;;; ; ; ; ; ;; ;; ; ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;; ; ; ; ;;;; ; ; ; ; ; ; ;;;;;; ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;; ; ; ; ; ; ;;;;;;; ; ;;;;; ; ; ; ; ;; ; ;;;; ;;; ; ; ; ; ; ; */ class Examples { Examples() {} // Examples of blobs: c1, c2, c3 ---------------------------------- Blob b1 = new Blob(new Posn(100, 300), 30); // center low Blob b2 = new Blob(new Posn(180, 20), 20); // top right corner Blob b3 = new Blob(new Posn(40, 360), 40); // bottom left corner // Testing the same method in the class Circle -------------------- boolean testSame1 = b1.same(new Blob(new Posn(100, 300), 30)); boolean testSame2 = b1.same(new Blob(new Posn(100, 300), 50)) == false; boolean testSame3 = b1.same(new Blob(new Posn(130, 300), 30)) == false; boolean testSame4 = b1.same(new Blob(new Posn(100, 140), 30)) == false; // Testing the move method in the class Circle ----------------- Blob movedcircle = b1.move(50, 50); boolean testMove1 = this.movedcircle.same( new Blob(new Posn(150, 350), 30)); boolean testMove2 = this.b2.move(-20, 20).same( new Blob(new Posn(160, 40), 20)); // Building the drawing world --------------------- // make an example of a drawing world World dw = new World(); // show the world as a canvas of the size 200, 400 boolean testWorldStart = this.dw.start(200, 400); // Drawing the circles:" -------------------------------------- // make a big blob and a small blob Blob bigBlob = new Blob(new Posn(100, 200), 50); Blob smallBlob = new Blob(new Posn(100, 100), 25); // draw the big blob and small blob in the given world boolean testBigBlobDraw = bigBlob.draw(this.dw); boolean testSmallBlobDraw = smallBlob.draw(this.dw); // Run: // > Examples e = new Examples(); // > e // ---- draw a blob in the center: ------- > e.b1.draw(e.dw) // ---- draw a blob in the top right: ---- > e.b2.draw(e.dw) // ---- draw a blob in the bottom left: -- > e.b3.draw(e.dw) }