Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.Sprite;
- import starling.core.Starling;
- public class SINE_MESHBATCH extends Sprite
- {
- public function SINE_MESHBATCH ()
- {
- with (stage) { frameRate = 60; color = 0x0; align = 'TL'; scaleMode = 'noScale'; }
- var starling : Starling = new Starling (Spiral, stage); // starling 2.1
- starling.showStats = true;
- starling.start ();
- }
- }
- }
- import flash.geom.Matrix;
- import starling.display.*;
- import starling.events.Event;
- import starling.core.Starling;
- /** @author SPANVEGA // CHRISTIAN **/
- final class Spiral extends Sprite
- {
- private var quad : Quad;
- private var batch : MeshBatch;
- private var angle : Number = 0,
- radius : Number = 0;
- private var m : Matrix = new Matrix ();
- private var fx : Number, fy : Number, // from
- tx : Number, ty : Number, // to
- cx : Number, cy : Number; // center
- public function Spiral ()
- {
- quad = new Quad (1, 1, 0xFFFFFF);
- quad.alignPivot ();
- addChild (batch = new MeshBatch ());
- cx = Starling.current.stage.stageWidth >> 1;
- cy = Starling.current.stage.stageHeight >> 1;
- addEventListener (Event.ENTER_FRAME, update);
- }
- private function update (e : Event) : void
- {
- tx = Math.sin (toRadians (angle)) * radius;
- ty = Math.cos (toRadians (angle)) * radius;
- //
- var q : Quad = line (quad, fx, fy, tx, ty);
- // offset to center
- q.x += cx;
- q.y += cy;
- batch.addMesh (q);
- //
- fx = tx, fy = ty;
- angle += 5.0;
- radius += 0.3;
- }
- private function toRadians (degrees : Number) : Number
- {
- return degrees * Math.PI / 180
- }
- private function line (quad : Quad, fx : Number, fy : Number, tx : Number, ty : Number) : Quad
- {
- var dx : Number = tx - fx,
- dy : Number = ty - fy,
- ds : Number = Math.sqrt (dx * dx + dy * dy);
- var a : Number, b : Number, c : Number, d : Number,
- sin : Number, cos : Number, rad : Number;
- // scale
- a = ds;
- // identity
- b = 0;
- c = 0;
- d = 1;
- // rotate
- rad = Math.atan2 (dy, dx);
- sin = Math.sin (rad);
- cos = Math.cos (rad);
- m.a = a * cos - b * sin;
- m.b = a * sin + b * cos;
- m.c = c * cos - d * sin;
- m.d = c * sin + d * cos;
- // translate
- m.tx = fx;
- m.ty = fy;
- //
- quad.transformationMatrix = m;
- return quad;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement