How do I draw shapes in a movie?
Added: 31 Jan 2009. Working example for Java
There are two options for drawing shapes using Transform. First you can draw them using the the classes that represent lines and curves:
ArrayList<ShapeRecord> list = new ArrayList<ShapeRecord>(); list.add(new ShapeStyle().setLineStyle(lineStyle) .setFillStyle(fillStyle).setAltFillStyle(altStyle) .setMove(-width/2, -height/2); list.add(new Line(width, 0)); list.add(new Line(0, height)); list.add(new Line(-width, 0)); list.add(new Line(0, -height)); movie.add(new DefineShape(identifier, bounds, fillStyles, lineStyles, new Shape(list)));
Alternatively you can use the Canvas class which provided a more abstract and certainly more concise API for drawing:
Canvas canvas = new Canvas(); canvas.setLineStyle(lineStyle); canvas.setFillStyle(fillStyle); canvas.move(-width/2, -height/2); canvas.rline(width, 0); canvas.rline(0, height); canvas.rline(-width, 0); canvas.rline(0, -height); canvas.closePath(); movie.add(canvas.defineShape(identifier));
The Canvas also simplifies shape drawing by managing the line and fill styles used to draw the shape and tracks the current drawing point so that the bounding box that encloses the shape is correctly sized.