Skip to content

Instantly share code, notes, and snippets.

@mieki256
Created March 30, 2015 13:21
Show Gist options
  • Save mieki256/81868ecb086d28b02f7b to your computer and use it in GitHub Desktop.
Save mieki256/81868ecb086d28b02f7b to your computer and use it in GitHub Desktop.
GIMP1.xのRGB交換相当っぽい感じのアニメをするHaxe+OpenFLソース
package;
import openfl.*;
import openfl.display.*;
import openfl.events.*;
/**
* Animation like GIMP 1.x RGB displace
* @author mieki256
*/
class Main extends Sprite
{
var sprs:Array<Bitmap>;
var r:Float;
var rspd:Float;
var ang:Float;
var step:Int;
var timer:Int;
var rootalpha:Float;
public function new()
{
super();
//Lib.current.stage.scaleMode = StageScaleMode.SHOW_ALL;
sprs = new Array<Bitmap>();
r = 200;
rspd = 0;
ang = 90.0;
step = 0;
timer = 0;
rootalpha = 0.0;
var list = ['r', 'g', 'b'];
for (fn in list) {
var bmp = new Bitmap(Assets.getBitmapData('img/' + fn + '.png'));
bmp.blendMode = BlendMode.ADD;
bmp.alpha = rootalpha;
addChild(bmp);
sprs.push(bmp);
}
addEventListener(Event.ENTER_FRAME, this_onEnterFrame);
}
private function this_onEnterFrame(e:Event):Void {
var cx = stage.stageWidth / 2;
var cy = stage.stageHeight / 2;
var a = ang;
for (bmp in sprs) {
bmp.x = r * Math.cos(a * Math.PI / 180.0) + cx - (bmp.width / 2);
bmp.y = r * Math.sin(a * Math.PI / 180.0) + cy - (bmp.height / 2);
bmp.alpha = rootalpha;
a += (360.0 / 3);
}
ang += 5.0;
switch(step) {
case 0:
rootalpha += 0.025;
if (rootalpha > 1.0 ) rootalpha = 1.0;
r -= r * 0.075;
if (r < 1.0) {
r = 0.0;
rspd = 0.0;
rootalpha = 1.0;
timer = 60;
step++;
}
case 1:
timer--;
if (timer < 0) step++;
case 2:
rspd += 0.05;
r += rspd;
rootalpha -= 0.01;
if (rootalpha < 0.0 ) {
r = 200;
rootalpha = 0.0;
timer = 60;
step++;
}
case 3:
timer--;
if (timer < 0) step = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment