Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 10-31-2003, 07:02 PM   #1
ferdymania
Registered User
 
Join Date: Oct 2003
Posts: 82
Default Drawing class - comments ? test pls

I am writing a class that will make using the drawing api easier to use...
it mirrors the java Graphics class
usage is :
ActionScript Code:
var gr:Graphics = new Graphics(depth); gr.setColor("0xff0000"); gr.setThick(3); gr.setFill("0x00ff00"); gr.drawLine(x,y,x1,y1); gr.drawRect(startx,starty,width, height); gr.fillRect(same); gr.drawOval(startx,starty,width,height); gr.fillOval( ...same..);

It doesnt draw a circle real well but if any genius bezier mathematicians can tell me where to put the control points for a circle then it would work properly for a circle..
any additions, refactoring, abuse welcome...
ActionScript Code:
class Graphics {     var mc;     var color:String;     var fill:String;     var thick:Number;     // constructor     public function Graphics(depth:Number) {         _root.createEmptyMovieClip("test1", depth);         mc = _root.test1;         // set defaults         color = "0x000000";         thick = 1;         fill = "0x666666";     }     // setters     function setColor(_color:String) {         color = _color;     }     // set thickness     function setThick(_thick:Number) {         thick = _thick;     }     // set fill     function setFill(_fill:String) {         fill = _fill;     }     //     //drawing functions     function drawLine(x1:Number, y1:Number, x2:Number, y2:Number) {         mc.lineStyle(thick, color);         mc.moveTo(x1, y1);         mc.lineTo(x2, y2);     }     function drawRect(x1:Number, y1:Number, width:Number, height:Number) {         mc.lineStyle(thick, color);         mc.moveTo(x1, y1);         mc.lineTo(x1+width, y1);         mc.lineTo(x1+width, y1+height);         mc.lineTo(x1, y1+height);         mc.lineTo(x1, y1);     }     // fillRect     function fillRect(x1:Number, y1:Number, width:Number, height:Number) {         mc.lineStyle(thick, color);         mc.moveTo(x1, y1);         mc.beginFill(fill);         mc.lineTo(x1+width, y1);         mc.lineTo(x1+width, y1+height);         mc.lineTo(x1, y1+height);         mc.lineTo(x1, y1);         mc.endFill();     }     // draw Oval     function drawOval(x:Number,y:Number, width:Number,height:Number){         mc.lineStyle(thick, color);         mc.moveTo(x,y+height/2);         mc.curveTo(x,y,x+width/2, y);         mc.curveTo(x+width,y,x+width, y+height/2);         mc.curveTo(x+width,y+height, x+width/2, y+height);         mc.curveTo(x,y+height, x, y+height/2);     }     // fill oval     function fillOval(x:Number,y:Number, width:Number,height:Number){         mc.lineStyle(thick, color);         mc.moveTo(x,y+height/2);         mc.beginFill(fill);         mc.curveTo(x,y,x+width/2, y);         mc.curveTo(x+width,y,x+width, y+height/2);         mc.curveTo(x+width,y+height, x+width/2, y+height);         mc.curveTo(x,y+height, x, y+height/2);         mc.endFill();     } }
ferdymania is offline   Reply With Quote
Old 11-02-2003, 05:17 AM   #2
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

i hope this can help

http://astronomy.swin.edu.au/~pbourke/curves/bezier/
__________________
€* GOD Is Near €*
Questions Don't PM for Questions . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
farafiro is offline   Reply With Quote
Old 11-02-2003, 08:12 AM   #3
ferdymania
Registered User
 
Join Date: Oct 2003
Posts: 82
Default

thanks faffy,
that is really complex maths...
i will have a good hard look at it...
my good friend deamothul worked out the code for the circle
and some stuff for gradient fills which i incorporated..
You could do some amazingly spirally animations
with all that maths but...
Here is my class as i have done up to now..
steve
Attached Files
File Type: zip drawing.zip (1.4 KB, 307 views)
ferdymania is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:50 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.