import draw.*; class FaceWorld extends World { boolean draw() { return this.theCanvas.start(100, 100) && new Face().draw(this); } boolean erase() { return this.theCanvas.drawRect(new Posn(0,0),100,100,new White()); } World onKeyEvent( String key ) { return this; } World onTick() { return this; } } abstract class Shape { abstract boolean draw( World w ); } class Disk extends Shape { Posn center; int radius; Color c; Disk( Posn center, int radius, Color c) { this.center = center; this.radius = radius; this.c = c; } boolean draw( World w ) { return w.theCanvas.drawDisk(this.center,this.radius,this.c); } } class Rectangle extends Shape { Posn topLeftCorner; int width; int height; Color c; Rectangle( Posn topLeft, int width, int height, Color c) { this.topLeftCorner = topLeft; this.width = width; this.height = height; this.c = c; } boolean draw( World w ) { return w.theCanvas.drawRect(topLeftCorner,width,height,c); } } class Face extends Shape { Shape base = new Disk(new Posn(50,50), 50, new Yellow()); Shape leftEye = new Eye(new Posn(30,30), new Blue()); Shape rightEye = new Eye(new Posn(70,30), new Blue()); Shape nose = new Nose(new Posn(50,50), new Red()); Shape mouth = new Mouth( new Posn(50,75), new Red(), new Yellow()); Face() { } boolean draw( World w ) { return base.draw(w) && leftEye.draw(w) && rightEye.draw(w) && nose.draw(w) && mouth.draw(w); } } class Eye extends Shape { Shape iris; Shape pupil; Eye( Posn center, Color irisColor ) { this.iris = new Disk( center, 10, irisColor ); this.pupil = new Disk( center, 5, new Black() ); } boolean draw( World w ) { return iris.draw(w) && pupil.draw(w); } } class Nose extends Shape { Shape n; Nose( Posn center, Color c) { this.n = new Disk( center, 8, c); } boolean draw( World w) { return n.draw(w); } } class Mouth extends Shape { Shape base; Shape cover; Mouth ( Posn center, Color mouthColor, Color baseColor ) { this.base = new Disk(center, 15, mouthColor); this.cover = new Rectangle(new Posn(center.x-20,center.y-20), 40, 20, baseColor); } boolean draw( World w ) { return this.base.draw(w) && this.cover.draw(w); } }