package; import haxe.Timer; import openfl.Vector; import openfl.display.Bitmap; import openfl.display.BitmapData; import openfl.display.Sprite; import openfl.Assets; import openfl.events.Event; class Main extends Sprite { var bitmap:Bitmap; var myShader = new MandelbrotShader(); var shader1:MyShader; public function new () { super (); var b = new Bitmap (Assets.getBitmapData ("assets/openfl.png")); var sprite = new Sprite(); sprite.addChild (b); sprite.x = 10; sprite.y = 10; sprite.width = 800; sprite.height = 600; addChild(sprite); // ----------- bitmap.shader ----------- //myShader = new MyShader(); myShader = new MandelbrotShader(); //myShader.custom_Value.value = [0.0]; myShader.time.value = [0.0]; //var bitmap = new Bitmap (Assets.getBitmapData ("assets/openfl.png")); bitmap = new Bitmap (new BitmapData(1,1)); bitmap.shader = myShader; bitmap.x = 50; bitmap.y = 150; bitmap.width = 400; bitmap.height = 200; bitmap.alpha = 0.9; addChild (bitmap); // ----------- drawQuads ----------- shader1 = new MyShader(); shader1.bitmap.input = new BitmapData(400, 200); shader1.bitmap.filter = LINEAR; shader1.custom_Value.value = [0.0]; // shader1.openfl_Alpha.value = [0.5]; // <- private //graphics.clear (); graphics.beginShaderFill (shader1); graphics.drawQuads ( Vector.ofArray ([0, 0, 400, 200]), null, Vector.ofArray ([20, 300]) ); // -------------------------- stage.addEventListener (Event.ENTER_FRAME, update); //stage.addEventListener (Event.RENDER, update); startTime = Timer.stamp(); } var test = 0.0; var startTime = 0.0; private function update (event:Event):Void { stage.invalidate (); myShader.time.value = [Timer.stamp()-startTime]; test += 0.01; shader1.custom_Value.value = [test]; bitmap.x = 50+test*50; graphics.clear (); graphics.beginShaderFill (shader1); graphics.drawQuads ( Vector.ofArray ([0, 0, 400, 200]), null, Vector.ofArray ([20+test*50, 300]) ); } }