AS Quiz #8
see http://actionsnippet.com/?p=2631
// see http://actionsnippet.com/?p=2631
package {
import flash.display.Graphics;
import flash.display.Sprite;
public class Foo extends Sprite{
public function Foo() {
var s:Sprite = new Sprite; s.x = s.y = 50;
addChild (s); drawStairs (s.graphics, 35);
}
public function drawStairs(g:Graphics, n:int):void {
g.lineStyle (2);
var i:int, s:Number = 10;
// going down stairs
for (i = 0; i < n; i++) {
g.lineTo (s * (1 + i), s * (i - 1));
g.lineTo (s * (2 + i), s * (i - 1));
g.lineTo (s * (1 + i), s * i);
g.lineTo (s * (1 + i), s * (i + 1));
}
// going up stairs
for (i = n - 1; i > -1; i--) {
g.moveTo (s * (1 + i), s * i);
g.lineTo (s * i, s * i);
}
// jump down
g.lineTo (0, s * n);
g.lineTo (s * n, s * n);
g.lineTo (s * (n + 1), s * (n - 1));
// going up stairs again
for (i = n - 1; i > -1; i--) {
g.lineTo (s * (2 + i), s * (i - 1));
g.moveTo (s * (1 + i), s * (i - 1));
}
}
}
}