<!doctype html> <html> <head> <script src="js/processing.js"></script> </head> <body> <canvas id="canvas"></canvas> </body> </html>
body { margin:0px; padding:0px; overflow:hidden; }
public static void main(String[] args) { size(800, 600); background(255); rectMode(CENTER); /* * Once implemented the following instance of Graphic * should draw a face with 2 eye ellipses and 1 rectangle * mouth. */ Ellipse leftEye = new Ellipse(25, 25, 20, 10); Ellipse rightEye = new Ellipse(75, 25, 20, 10); Rect mouth = new Rect(50, 75, 40, 10); Graphic graphic = new Graphic(100, 100); graphic.add(leftEye); graphic.add(rightEye); graphic.add(mouth); graphic.draw(); }
abstract class Component { float x, y; int w, h; Component parent; void init(float _x, float _y, int _w, int _h) { x = _x; y = _y; w = _w; h = _h; } void translate(float dx, float dy) { x += dx; y += dy; } //implement in subclass abstract void draw() {} }
public class Graphic extends Component { private ArrayList
children = new ArrayList
(); Graphic(float x, float y) { init(x, y); } public void draw() { //implement } public void add(Component child) { //implement } public void remove(Component child) { //implement } }
public class Rect extends Component { Rect(float x, float y, int w, int h) { init(x, y, w, h); } public void draw() { //implement } }
public class Ellipse extends Component { Ellipse(float x, float y, int w, int h) { init(x, y, w, h); } public void draw() { //implement } }