
This is the library used in the Haxe Flash Tutorial. This page is a parameter reference, for usage examples please look into the chapters of the tutorial.
If you are ready to code, take a look at the end to see how you could use the library.
Drawing a five corner star, hollywood like. There are options to draw an empty, a half- and a filled star.
The design of the star is based on the horizontal line of the upper edge, you could easily construct a star of your own with the usual tools: draw a circle, mark five points of equal distance on them, starting from p1 at 12 o'clock going clockwise to p5.
Now line from p1 to p3, going to p5, p2, p4 and finally p1. Given the radius and the intersection between the lines p1,p3 and p2,p5 you could calculate the inner angle which in turn could be used to calculate coordinates for the inner five points.
If someone finds some time left, he might add this procedure as a flash movie clip.
static public function drawStar(
g:Graphics, // Graphics object to draw in, could be Shape, Sprite, MovieClip, etc.
x:Int, // x-coordinate of center point (the middle of the star)
y:Int, // y-coordinate of starting (top of the star)
r:Float, // radius of the star (see explanation)
fill:Int, // fill mode: 0=nothing, 1=half, 2=full
col0:Int, // empty-border color
fillcol0:Int, empty-full color
col:Int, // full-border color
fillcol:Int, // full-fill color
alpha:Float // alpha value, transparency 1=opaque,0.5=semi-transparent,0=invisible
){
static public function drawStar(
g:Graphics, // Graphics object to draw in, could be Shape, Sprite, MovieClip, etc.
x:Int, // x-coordinate of center point (the middle of the star)
y:Int, // y-coordinate of starting (top of the star)
r:Float, // radius of the star (see explanation)
fill:Int, // fill mode: 0=nothing, 1=half, 2=full
col0:Int, // empty-border color
fillcol0:Int, empty-full color
col:Int, // full-border color
fillcol:Int, // full-fill color
alpha:Float // alpha value, transparency 1=opaque,0.5=semi-transparent,0=invisible
){
var phi : Float = 2*Math.PI/5;
// (p2y-p1y)(p3x-p1x)/(p3y-p1y)
var r2 : Float = ((Math.cos(phi*1)*r)-r)*((Math.sin(phi*2)*r)-0)/(Math.cos(phi*2)*r-r);
r2 = Math.sqrt(r2*r2+Math.pow(Math.cos(phi)*r,2));
g.lineStyle(1,(fill==0 ? col0 : col),alpha,true,LineScaleMode.NORMAL,CapsStyle.ROUND,JointStyle.ROUND);
g.beginFill((fill==2 ? fillcol : fillcol0),alpha);
g.moveTo(x,y+r-r);
g.lineTo(x+Math.sin(0.5*phi)*r2,y+r-Math.cos(0.5*phi)*r2);
g.lineTo(x+Math.sin(1*phi)*r,y+r-Math.cos(1*phi)*r);
g.lineTo(x+Math.sin(1.5*phi)*r2,y+r-Math.cos(1.5*phi)*r2);
g.lineTo(x+Math.sin(2*phi)*r,y+r-Math.cos(2*phi)*r);
g.lineTo(x+Math.sin(2.5*phi)*r2,y+r-Math.cos(2.5*phi)*r2);
g.lineTo(x+Math.sin(3*phi)*r,y+r-Math.cos(3*phi)*r);
g.lineTo(x+Math.sin(3.5*phi)*r2,y+r-Math.cos(3.5*phi)*r2);
g.lineTo(x+Math.sin(4*phi)*r,y+r-Math.cos(4*phi)*r);
g.lineTo(x+Math.sin(4.5*phi)*r2,y+r-Math.cos(4.5*phi)*r2);
g.lineTo(x,y+r-r);
g.endFill();
if(fill!=0 && fill!=2){
g.lineStyle(0,col,alpha,true,LineScaleMode.NORMAL,CapsStyle.ROUND,JointStyle.ROUND);
g.beginFill(fillcol,alpha);
g.moveTo(x+Math.sin(2.5*phi)*r2,y+r-Math.cos(2.5*phi)*r2);
g.lineTo(x+Math.sin(3*phi)*r,y+r-Math.cos(3*phi)*r);
g.lineTo(x+Math.sin(3.5*phi)*r2,y+r-Math.cos(3.5*phi)*r2);
g.lineTo(x+Math.sin(4*phi)*r,y+r-Math.cos(4*phi)*r);
g.lineTo(x+Math.sin(4.5*phi)*r2,y+r-Math.cos(4.5*phi)*r2);
g.lineTo(x,y+r-r);
g.endFill();
}
}
Drawing a Play button, which is semi transparent. Width and height and rounded corner are given as parameter.
The return value is a Shape object, which could be attached to events and placed on the stage.
static public function drawPlayButton(
w:Int, // width of the rectangle
h:Int, // height of the rectangle
r:Int // corner radius 16
):Shape{
static public function drawPlayButton(
w:Int, // width of the rectangle
h:Int, // height of the rectangle
r:Int // corner radius 16
):Shape{
var playBtn : Shape = new Shape();
var g : Graphics = playBtn.graphics;
g.lineStyle(1,0xe5e5e5);
var colors:Array<Int> = [0xF5F5F5, 0xA0A0A0];
var alphas:Array<Int> = [1, 1];
var ratios:Array<Int> = [0, 255];
var matrix:Matrix = new Matrix();
matrix.createGradientBox(w-2, h-2, Math.PI/2, 0, 0);
g.beginGradientFill(GradientType.LINEAR,
colors,
alphas,
ratios,
matrix,
SpreadMethod.PAD,
InterpolationMethod.LINEAR_RGB,
0);
g.drawRoundRect(0,0,w,h,r,r);
g.endFill();
// draw a triangle
g.lineStyle(1,0x808080);
g.beginFill(0x0);
g.moveTo((w-20)/2,5);
g.lineTo((w-20)/2+20,h/2);
g.lineTo((w-20)/2,h-5);
g.lineTo((w-20)/2,5);
g.endFill();
// add the drop-shadow filter
var shadow : DropShadowFilter = new DropShadowFilter(
4,45,0x000000,0.8,
4,4,
0.65,BitmapFilterQuality.HIGH, false, false
);
var af : Array<Dynamic> = new Array();
af.push(shadow);
playBtn.filters = af;
playBtn.alpha = 0.5;
return playBtn;
}
All you need to use the library within you own projects is setting the class path:
haxe -cp lib-path
For instance if you have extracted the library into a subdirectory of your current working directory and your class is called MyHaxe, then the following would include the library:
haxe -cp haxeflashtutorial-0.0.1/haxe -main MyHaxe
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses.
Copyright (C) 2008 by Siegmund Gorr