Today I’ve been scouting the internet for a specific class, one that draws shapes.
I remembered that some time ago I read an article on the Adobe Dev site by Ric Ewing about drawing shapes. But this was all done in AS2… and I hated AS2! (and so should you
! ) But I found a AS3 version. Its redone by a guy from Bristol, Aden Forshaw.
He also posted a really cool tool that generates code and allows you to visually adjust the settings of an object. Go check it out.
After looking at his code I re-wrote it so it takes the Graphics Class instead of only allowing Sprites, changed datatypes, optimized loops, optimized math operations and threw errors where needed.
So here is the new class for you to download and an example on how to use it. The code below actually produces the image on the top of this post):
var s : Shape = new Shape( ); s.graphics.lineStyle( 4, 0xE16606 ); DrawingShapes.drawArc( s.graphics, 50, 50, 10, 150, 60 ); s.graphics.lineStyle( 3, 0x000000 ); DrawingShapes.drawBurst( s.graphics, 80, 60, 3, 15, 6, 27 ); s.graphics.lineStyle( 1, 0x3C3C39 ); DrawingShapes.drawDash( s.graphics, 120, 60, 150, 80, 2, 2 ); s.graphics.lineStyle( 3, 0xE16606 ); DrawingShapes.drawGear( s.graphics, 200, 60, 13, 31, 26, 0, 7, 13 ); s.graphics.lineStyle( 3, 0x0074B9 ); DrawingShapes.drawPolygon( s.graphics, 270, 60, 7, 30, 45 ); s.graphics.lineStyle( 2, 0x000000 ); DrawingShapes.drawStar( s.graphics, 340, 60, 18, 24, 19, 27 ); s.graphics.lineStyle( 2, 0xFFCC00 ); DrawingShapes.drawWedge( s.graphics, 400, 60, 30, 309, 209 ); s.graphics.lineStyle( 2, 0x0074B9 ); DrawingShapes.drawLine( s.graphics, 440, 80, 30, DrawingShapes.VERTICAL_LINE ); addChild( s );
And here is a pastie especially for those who don’t like the zip format:




on Apr 20th, 2010 at 6:46 pm
why not put the code in a GitHub Gist or a pastie, so i don’t need to download the zip file…
on Apr 22nd, 2010 at 12:16 am
[...] Nice work Sid, i’ve ammended the demo below to include his class and the associated source code. His related article… [...]
on Jun 6th, 2010 at 5:01 pm
[...] 9. Programmatic drawing (assets, gradients, fills, lines etc.) Since Flash is all about being visual, take some time to understand why you need to draw stuff in comparison to using assets. Drawing is much faster and takes up less memory. Lots of assets bog down your application. http://www.funky-monkey.nl/blog/2010/04/20/drawing-shapes-in-as3-a-class-to-draw-an-arc-star-gear-co... [...]