Name: shapeStyle/endShapeStyle - control shapes creates w/ drawing methods with offset, scale and rotation
Author: senocular: www.senocular.com
Date: 1899-12-31T00:07:00.600
Documentation:
MovieClip SHAPESTYLE: adds capability to alter drawing
methods of a movieclip with an optional rotation, scale,
and/or position offset.
- opperates much like beginFill() and endFill() with a 'beginner' and an 'ender'
myMovieClip.shapeStyle(x, y, xscale, yscale, rotation);
// ... drawing methods
myMovieClip.endShapeStyle();
or
myMovieClip.shapeStyle(movieClipOrObject);
// ... drawing methods
myMovieClip.endShapeStyle();
(shapeStyle)
Arguments:
- can take 2 kinds of arguments: either a comma seperated list of properties or an object
or movieclip with those properties within (in underscore (_) format)
- x: x-offset of all drawing methods called following shapeStyle
- y: y-offset of all drawing methods called following shapeStyle
- xscale: x-scale of drawing methods
- yscale: y-scale of drawing methods
- rotation: rotation of drawing methods
- If an object or movieclip is passed, the above properties will be set by that
object/movieclip's _x, _y, _xscale, _yscale and/or _rotation.
Returns:
- nothing
(endShapeStyle)
Arguments:
- none
Returns:
- nothing
Example:
// this makes a parachute shape but uses
// shapeStyle to rotate it 45 degress at
// a scale of 200% and an offset of 200
// along the x axis and 100 along the y
this.lineStyle(1,0,100)
this.shapeStyle(200,100,200,200, 45);
this.moveTo(-50,0)
this.lineTo(0,100);
this.lineTo(50,0);
this.curveTo(0,-20, -50,0)
this.curveTo(0,-80, 50,0)
this.endShapeStyle();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
MovieClip.prototype.shapeStyle = function(x, y, xscale, yscale, rotation){
this.moveTo = arguments.callee.moveTo;
this.lineTo = arguments.callee.lineTo;
this.curveTo = arguments.callee.curveTo;
if (typeof x == "number") this.$SSProps = {xo:x, yo:y, xs:xscale/100, ys:yscale/100, r:rotation*Math.PI/180};
else this.$SSProps = {xo:x._x, yo:x._y, xs:x._xscale/100, ys:x._yscale/100, r:x._rotation*Math.PI/180};
ASSetPropFlags(this,"$SSProps",1);
};
MovieClip.prototype.endShapeStyle = function(){
delete this.moveTo;
delete this.lineTo;
delete this.curveTo;
delete this.$SSProps;
};
MovieClip.prototype.shapeStyle.moveTo = function(x,y){
MovieClip.prototype.shapeStyle.basic.call(this,x,y, "moveTo");
};
MovieClip.prototype.shapeStyle.lineTo = function(x,y){
MovieClip.prototype.shapeStyle.basic.call(this,x,y, "lineTo");
};
MovieClip.prototype.shapeStyle.basic = function(x,y, func){
if (this.$SSProps.r){
var c = Math.cos(this.$SSProps.r), s = Math.sin(this.$SSProps.r);
var tx = x*c-y*s;
y = x*s+y*c;
x = tx;
}
if (this.$SSProps.xs) x *= this.$SSProps.xs;
if (this.$SSProps.ys) y *= this.$SSProps.ys;
if (this.$SSProps.xo) x += this.$SSProps.xo;
if (this.$SSProps.yo) y += this.$SSProps.yo;
MovieClip.prototype[func].call(this, x,y);
};
MovieClip.prototype.shapeStyle.curveTo = function(cx,cy,x,y){
if (this.$SSProps.r){
var c = Math.cos(this.$SSProps.r), s = Math.sin(this.$SSProps.r);
var tx = x*c-y*s;
y = x*s+y*c;
x = tx;
tx = cx*c-cy*s;
cy = cx*s+cy*c;
cx = tx;
}
if (this.$SSProps.xs){
cx *= this.$SSProps.xs;
x *= this.$SSProps.xs;
}
if (this.$SSProps.ys){
cy *= this.$SSProps.ys;
y *= this.$SSProps.ys;
}
if (this.$SSProps.xo){
cx += this.$SSProps.xo;
x += this.$SSProps.xo;
}
if (this.$SSProps.yo){
cy += this.$SSProps.yo;
y += this.$SSProps.yo;
}
MovieClip.prototype.curveTo.call(this, cx,cy,x,y);
};
ASSetPropFlags(MovieClip.prototype,"shapeStyle,endShapeStyle",1);