An easy to use AS3 shape drawing class, gear, cogs, wedge, arc, star, burst
Every other Sunday i'm going to try and release some free code. Things like projects i thought had legs, got to the prototype stage but never had time to finish, or Actionscript libraries that i think other might find useful.
In this case i'm releasing my shape drawing AS3 class. This is mainly just an Actionscript 3 implementation of the hard work done by both Kevin Williams and Ric Ewing. I've also used a Minimal Comps Slider as well and included the slightly amended code for that which does not require the Flex SDK (makes it easier for people not familiar with it).
Any comments, suggestions, or shapes you'd like to add just comment or send me a mail.
Enjoy, Aden.
EDIT -
Sidney de Koning has done exactly what i hoped and taken this on and made some improvements. Along with some nice speed tweaks, each method now takes in a reference to a Graphics instance instead of a Sprite class, improving the performance and making it move useful.
Nice work Sid, i've ammended the demo below to include his class and the associated source code. His related article...
April 19th, 2010 - 19:39
Hey thanks! I was about to write my own wedge class, looks like I’m going to save some time!
April 19th, 2010 - 19:43
Nice !
Very useful for drawing at runtime things like gears
Hope you’ll go on with your #FreeCodeSunday ! ^^
April 20th, 2010 - 13:52
Nice one! Thanks for sharing!
I kindof re-wrote the class to take an instance of the Graphics class, so you can not only draw in Sprites but also Shapes and MovieClips. (Because Sprites and MovieClips add extra weight to your application, for movieclips it is because they have a timeline) And you are not bound to drawing one shape in one Sprite but you can also draw multiple shapes in the Graphics layer. And i did some othe optimisations. Shall i put up a link for you? Mail me if you like it.
Cheers,
Sid
April 20th, 2010 - 14:11
Sorry what i meant was this, was to fast with the submit button..;
Nice one! Thanks for sharing!
I kindof re-wrote the class to take an instance of the Graphics class, so you can not only draw in Sprites but everything that has makes use of the Graphics Class. It is somethimes better to draw in Shapes, because they are lighter in KB’s. And now you are not bound to drawing one shape in one Sprite instance but you can also draw multiple shapes on/in the Graphics layer. And i did some othe optimisations and throw some argument errors where needed.
Shall i put up a link for you? Mail me if you like it.
Cheers,
Sid
April 20th, 2010 - 14:21
Absolutely Sid, just mail it over and i’ll add it to the post.
I must admit it was an oversight to use Sprite as the minimum DisplayObject extendee, but this is what releasing code to the internet is all about, collaborating to get the best end result.
April 20th, 2010 - 17:16
I know
Really cool if you can add it to your post.
And once again thanks for posting this, this saved me alot of time!
This is the link: http://www.funky-monkey.nl/blog/2010/04/20/drawing-shapes-in-as3-a-class-to-draw-an-arc-star-gear-cog-wedge-and-a-burst/
Cheers,
Sid
August 17th, 2010 - 17:22
So free as in MIT license free? Thanks!
January 10th, 2011 - 09:14
Nice work.i was in search of this type of shapes..
i have a doubt.how can this class be reused for dynamic drawing with mouse.I mean something like polystar tool in flash.
like we can click the stage and move then accordingly a star.polygon is coming and the width increases according to distance between first point and mouseX value and if you rotate the mouse then the angle of the sprite is changed…
can anyone tell me how to do that with the help of this class.
March 3rd, 2011 - 18:31
Very nice et usefull work. Thanks for it… Perhaps you should add a parameter to turn angle between degrees and radians… I use in game with many redraw, and it’s a waist of time to convert radian angle to degree and re-convert it in your class in radians.