Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.Sprite;
- import starling.core.Starling;
- public class LINE_MESHBATCH extends Sprite
- {
- public function LINE_MESHBATCH ()
- {
- with (stage) { frameRate = 60; color = 0x0; align = 'TL'; scaleMode = 'noScale'; }
- var starling : Starling = new Starling (Lines, stage); // starling 2.1
- starling.showStats = true;
- starling.start ();
- }
- }
- }
- import flash.geom.Matrix;
- import starling.display.*;
- import starling.events.Event;
- /** @author SPANVEGA // CHRISTIAN **/
- final class Lines extends Sprite
- {
- private var pt_1 : Quad, pt_2 : Quad,
- line : Quad;
- private var m : Matrix = new Matrix ();
- private var batch : MeshBatch;
- public function Lines ()
- {
- line = new Quad (1, 1, 0xFFFFFF);
- line.alignPivot ();
- pt_1 = new Quad (4, 4, 0x850000);
- pt_1.alignPivot ();
- pt_2 = new Quad (4, 4, 0x0085FF);
- pt_2.alignPivot ();
- addChild (batch = new MeshBatch ());
- addEventListener (Event.ENTER_FRAME, update);
- }
- private function update (e : Event) : void
- {
- batch.clear ();
- for (var i : int = 0; i < 1000; i++)
- {
- pt_1.x = Math.random () * 465;
- pt_1.y = Math.random () * 465;
- pt_2.x = Math.random () * 465;
- pt_2.y = Math.random () * 465;
- var dx : Number = pt_2.x - pt_1.x,
- dy : Number = pt_2.y - pt_1.y,
- 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 = pt_1.x;
- m.ty = pt_1.y;
- //
- line.transformationMatrix = m;
- batch.addMesh (line);
- batch.addMesh (pt_1);
- batch.addMesh (pt_2);
- }
- }
- }
Add Comment
Please, Sign In to add comment