// Lab 3: WorldDemo.bjava sample program // Show how to use the Canvas class to display a drawing import draw.*; import colors.*; import geometry.*; // a class to represent a world with one dying red sun class MiniWorld{ int x; MiniWorld(int x){ this.x = x; } // draw the sun boolean draw(Canvas c){ return c.drawDisk(new Posn(100, 50), this.x, new Red()); } // erase the sun - clear the canvas boolean erase(Canvas c){ return c.drawRect(new Posn(0, 0), 200, 200, new White()); } } class Examples{ Examples() {} // define a new world MiniWorld mw = new MiniWorld(30); // define a new canvas Canvas c = new Canvas(200, 200); // display the canvas and draw a disk on the canvas boolean makeDrawing = this.c.show() && this.mw.draw(this.c); /* Try the following in the Interactions window: > Examples e = new Examples(); > e.mw.erase(e.c) true > e.mw.draw(e.c) true > */ }