Skip to content

Instantly share code, notes, and snippets.

@SimonRichardson
Last active December 14, 2015 16:48
Show Gist options
  • Save SimonRichardson/5117330 to your computer and use it in GitHub Desktop.
Save SimonRichardson/5117330 to your computer and use it in GitHub Desktop.
Shallow graphics api.
interface IDrawable {}
class DisplayObject {
public function new(drawable: IDrawable){}
}
// Different drawable items
class Bitmap implements IDrawable {}
class Graphics implements IDrawable {}
class Movie implements IDrawable {}
// So you can do the following
var graphics = new Graphics();
graphics.drawCiricle(0, 0, 50, 50);
var disp0 = new DisplayObject(graphics);
disp0.x = 100;
var disp1 = new DisplayObject(graphics);
disp1.x = 200;
var disp2 = new DisplayObject(graphics);
disp2.x = 100;
// Then doing the following will update all 3 display objects.
graphics.drawRect(50, 50, 50, 50);
// Immutable graphics
var graphics = new ImmutableGraphics();
graphics = graphics.drawCircle(0, 0, 50, 50);
var disp0 = new DisplayObject(graphics);
var disp1 = new DisplayObject(graphics);
var disp2 = new DisplayObject(graphics);
// This doesn't do anything as the graphics are immutable.
graphics.drawRect(50, 50, 50, 50);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment