Skip to content

Instantly share code, notes, and snippets.

@YellowAfterlife
Created August 18, 2013 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YellowAfterlife/dea6ad6f65162e865899 to your computer and use it in GitHub Desktop.
Save YellowAfterlife/dea6ad6f65162e865899 to your computer and use it in GitHub Desktop.
package ;
import flash.Lib;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Point;
import flash.geom.Matrix;
class Main {
var flowSurface:BitmapData;
var flowBitmap:Bitmap;
var flowPoint:Point;
var flowMatrix:Matrix;
public function new() {
var flowSource:BitmapData = openfl.Assets.getBitmapData("img/water.png"); // 256x256 PNG
flowSurface = new BitmapData(768, 768, true, 0);
flowPoint = new Point();
for (i in 0 ... 9) {
flowPoint.x = (i % 3) * 256;
flowPoint.y = Std.int(i / 3) * 256;
flowSurface.copyPixels(flowSource, flowSource.rect, flowPoint);
}
flowBitmap = new Bitmap(new BitmapData(480, 320, true, 0));
Lib.current.addChild(flowBitmap);
flowBitmap.stage.frameRate = 60;
flowMatrix = new Matrix();
flowBitmap.addEventListener(flash.events.Event.ENTER_FRAME, onEnterFrame);
onEnterFrame(null);
}
function onEnterFrame(e:Dynamic):Void {
var t:Float = Lib.getTimer() / 1000;
#if copyPixels
flowPoint.x = -((t * 100) % 256);
flowPoint.y = -((t * 70) % 256);
flowBitmap.bitmapData.copyPixels(flowSurface, flowSurface.rect, flowPoint);
#else
flowMatrix.tx = -((t * 100) % 256);
flowMatrix.ty = -((t * 70) % 256);
flowBitmap.bitmapData.draw(flowSurface, flowMatrix);
#end
}
@:keep public static function main() {
new Main();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment