By Zevan | April 15, 2009
Actionscript:
-
x = stage.stageWidth / 2;
-
y = stage.stageHeight / 2;
-
scaleX = scaleY = 3;
-
-
var t:Number =-5;
-
var xp:Number = 0;
-
var yp:Number = 0;
-
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
function onLoop(evt:Event):void {
-
xp = t;
-
yp = sinh(t);
-
-
graphics.lineStyle(0,0);
-
if (t == -5){
-
graphics.moveTo(xp, yp);
-
}else{
-
graphics.lineTo(xp, yp);
-
}
-
if (t> 5){
-
removeEventListener(Event.ENTER_FRAME, onLoop);
-
}
-
t+=.2;
-
}
-
function sinh(x:Number):Number{
-
return (Math.pow(Math.E, x) - Math.pow(Math.E, -x)) * 0.5;
-
}
Just a quick plot to test the sinh() function from a few days ago...
Posted in Math | Tagged actionscript, flash |
By Zevan | April 14, 2009
Actionscript:
-
var size:Array = [1, 1.5, .5, 1, .4, 1, 1, 1, .2, 1.1]
-
var boxes:Array = new Array();
-
var spacing:Number = 4;
-
var container:Sprite = Sprite(addChild(new Sprite()));
-
container.x = container.y = 100;
-
-
for (var i:int = 0; i<size.length; i++){
-
var box:Sprite = makeBox();
-
var prev:int = i - 1;
-
box.scaleX= box.scaleY = size[i];
-
if (i == 0){
-
box.y = 10;
-
}else{
-
// here's the trick
-
// if you animate the height property you need to do this again and again:
-
box.y = boxes[prev].y + boxes[prev].height/2+ box.height/2 + spacing
-
}
-
boxes.push(box);
-
}
-
-
function makeBox():Sprite{
-
var box:Sprite = Sprite(container.addChild(new Sprite()));
-
with (box.graphics) beginFill(0xFF0000), drawRect(-50,-10, 100, 20);
-
return box;
-
}
Sometimes you need to position a bunch of Sprites or MovieClips that are different sizes - and you want to keep the spacing between them the same. This snippet shows a simple example of this.
For more info you could also do this tutorial that I wrote on learningactionscript3.com
Posted in UI, misc | Tagged actionscript, flash |
By Zevan | April 13, 2009
Recently launched a new project over at shapevent.com. If your enjoy sketchbooks, drawings and interactive ugliness... have a look here:
Shapevent Log
Many of the techniques covered in the code on this website will be used in shapevent log entries... no rss feed yet, but I'll have one up for it in the next few days....
By Zevan | April 13, 2009
Actionscript:
-
function sinh(x:Number):Number{
-
return (Math.pow(Math.E, x) - Math.pow(Math.E, -x)) * 0.5;
-
}
-
-
function cosh(x:Number):Number{
-
return (Math.pow(Math.E, x) + Math.pow(Math.E, -x)) * 0.5;
-
}
Needed sinh and cosh today. Easy enough to create with existing math functions. If you needed more speed you could inline these and replace Math.E with 2.71828183.
Got the math over at wikipedia (as usual).
Posted in Math, misc | Tagged actionscript, flash |