In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

chart

Get Adobe Flash player
by phcacique 25 Apr 2014
    Embed
/**
 * Copyright phcacique ( http://wonderfl.net/user/phcacique )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/psDV
 */

package {
    import flash.text.TextFormatAlign;
    import flash.text.TextFormat;
    import flash.text.TextField;
    import flash.display.JointStyle;
    import flash.display.LineScaleMode;
    import flash.display.CapsStyle;
    import flash.filters.DropShadowFilter;
    import flash.display.MovieClip;
    import flash.display.Shape;
    import flash.display.Sprite;
    public class PieChart extends Sprite {
        
        public var deg_to_rad:Number = 0.0174532925;
        
        public function PieChart() {
            
            var chart:MovieClip = drawChart(0xF54767,248,300,100);
            addChild(chart);
            chart.x = chart.width;
            chart.y = chart.height;
            
            var chart2:MovieClip = drawChart(0x61B8FF,248,300,50);
            addChild(chart2);
            chart2.x = chart.x + chart.width/2 + chart2.width/2;
            chart2.y = chart.y ;
            
            
            
            
            
        }
        
        public function drawChart(color:uint, value:Number, total:Number, radius:Number):MovieClip {
            
            var angle:Number = value*360/total;            
            var chart:MovieClip = new MovieClip();
            
            var linesize:int = radius*20/150;
            
            var base:MovieClip = new MovieClip();
            chart.addChild(base);
            base.graphics.lineStyle(linesize,0xe0e0e0,1);
            draw_arc(base,0,0,radius,0,360,1);            

            var colored:MovieClip = new MovieClip();
            chart.addChild(colored);
            colored.graphics.lineStyle(linesize,color,1,false,LineScaleMode.NORMAL,CapsStyle.NONE,JointStyle.BEVEL);
            draw_arc(colored,0,0,radius,-90,angle-90,1);accessibilityImplementation
            
            var color2:uint = darkenColor(color,50);
            var dropShadow:DropShadowFilter = new DropShadowFilter();
            dropShadow.distance = 4*radius/150;
            dropShadow.angle = 45;
            dropShadow.color = color2;
            dropShadow.alpha = .8;
            dropShadow.blurX = 5*radius/150;
            dropShadow.blurY = 5*radius/150;
            dropShadow.strength = 1;
            dropShadow.quality = 15;
            dropShadow.inner = true;
            dropShadow.knockout = false;
            dropShadow.hideObject = false;
            colored.filters = new Array(dropShadow);
            
            var textfield:TextField = new TextField();           
            textfield.width = 2*radius;
            textfield.textColor = color;
                        
            var textFormat:TextFormat = new TextFormat();
            textFormat.size = radius/2;
            textFormat.align = TextFormatAlign.CENTER;
            textfield.defaultTextFormat = textFormat;
            
            textfield.text = value.toString();
            chart.addChild(textfield);
            textfield.x = -radius;
            textfield.y = -textfield.textHeight/2;
            
            return chart;
       }
       
       public function darkenColor(hexColor:Number, percent:Number):uint{

            if(isNaN(percent))
                percent=0;
            if(percent>100)
                percent=100;
            if(percent<0)
                percent=0;       

            var factor:Number = 1-(percent/100);
            var rgb:Object = hexToRgb(hexColor);

            rgb.r*=factor;
            rgb.b*=factor;
            rgb.g*=factor;

            return rgbToHex(Math.round(rgb.r),Math.round(rgb.g),Math.round(rgb.b));

        }
        
        public function rgbToHex(r:Number, g:Number, b:Number):uint {
                return(r<<16 | g<<8 | b);
        }

        public function hexToRgb (hex:Number):Object{
            return {r:(hex & 0xff0000) >> 16,g:(hex & 0x00ff00) >> 8,b:hex & 0x0000ff};
        }
        
        public function draw_arc(movieclip:MovieClip, center_x:Number ,center_y:Number ,radius:Number ,angle_from:Number ,angle_to:Number ,precision:Number ):void {

            var angle_diff:Number =angle_to-angle_from;
            var steps:int =Math.round(angle_diff*precision);
            var angle:Number =angle_from;
            var px:Number = center_x+radius*Math.cos(angle*deg_to_rad);
            var py:Number = center_y+radius*Math.sin(angle*deg_to_rad);

            movieclip.graphics.moveTo(px,py);
            for (var i:int=1; i<=steps; i++) {
                angle = angle_from+angle_diff/steps*i;
                movieclip.graphics.lineTo(center_x+radius*Math.cos(angle*deg_to_rad),center_y+radius*Math.sin(angle*deg_to_rad));
            }
                        
        
        }
        
    }
}