/** * Copyright (c) 2006 Peter Goodman * Licensed under the MIT License: * http://www.opensource.org/licenses/mit-license.php */ //-------------------------------------------- // Class to deal with drawing things. //-------------------------------------------- class FA.build.draw_fns extends FA.Query { private var info:Object; private var line_width:Number; private var line_color:Number; private var line_transparency:Number; private var fill_transparency:Number; //-------------------------------------------- // Draw a shape. //-------------------------------------------- public function draw (shape_info:Object) : FA.Query { var shape:String = shape_info.shape.toLowerCase(); if (this[shape].constructor == Function and _object instanceof MovieClip) { info = shape_info; line_width = info.lineWidth || 1; line_color = info.lineColor || 0x000000; line_transparency = info.lineAlpha || 100; fill_transparency = info.fillAlpha || 100; //-------------------------------------------- // Create the shape and deal with filling it in // if necessary. //-------------------------------------------- if (info.fillColor != undefined) { _object.beginFill(info.fillColor, fill_transparency); } _object.lineStyle(line_width, line_color, line_transparency); this[shape].apply(this, []); if (info.fillColor != undefined) { _object.endFill(); } } return this; } //-------------------------------------------- // Draw a circle. Format: // { // radius: 10, // _x: 100, // _y: 100 // } //-------------------------------------------- private function circle () : Void { var x:Number; var y:Number; var a:Number; for (a = 0; a <= 360; a++) { x = info._x + info.radius * Math.cos(a * Math.PI / 180); y = info._y + info.radius * Math.sin(a * Math.PI / 180); with (_object) { if (a == 0) { moveTo(x, y); } lineTo(x, y); } } } //-------------------------------------------- // Draw a rectangle. Format: // { // width: 100, // height: 100, // } //-------------------------------------------- private function rectangle () : Void { _object.moveTo(info._x, info._y); _object.lineTo(info.width, info._y); _object.lineTo(info.width, info.height); _object.lineTo(info._x, info.height); } //-------------------------------------------- // Draw a triangle. // { // a: [x, y], // left // b: [x, y], // right // _x: 100, // _y: 100 // } //-------------------------------------------- private function triangle () : Void { _object.moveTo(info._x, info._y); _object.lineTo(info.b[1], info.b[1]); // c _object.lineTo(info.a[0], info.a[1]); // a _object.lineTo(info._x, info._y); // b } }