/**
* Copyright h_sakurai ( http://wonderfl.net/user/h_sakurai )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9eNjA
*/
// forked from mahbubeh_pardis's forked from: Rainbow Preloader
// forked from Vladik's Rainbow Preloader
package {import flash.display.Sprite;import flash.events.Event;[SWF(backgroundColor=0x84B7EE, width=465, height=456,
frameRate=60 )]
public class FakeStage extends Sprite {
public var bgColor:uint = 0x1A1A1A;
public function FakeStage() {stage ? init() : addEventListener(Event.ADDED_TO_STAGE,init);}
private function init(e:Event = null):void {removeEventListener(Event.ADDED_TO_STAGE,init);fillBg();addChild(new Main());stage.addEventListener(Event.RESIZE,fillBg);}private function fillBg(e:Event=null):void{graphics.clear();graphics.beginFill(bgColor);graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);graphics.endFill();}}}
import flash.display.Stage;
import flash.filters.GlowFilter;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.display.Sprite;
import flash.display.Graphics;
import flash.geom.ColorTransform;
import flash.display.BitmapData;
import flash.display.Bitmap;
import frocessing.color.ColorRGB;
import frocessing.color.ColorHSV;
//TODO simplify this code to one class [ex Sprite]
/*
PLAY AROUND WITH THIS VARIABLES.
*/
class Vars
{
//The sprite scale - the preloader size (quick and dirty...) try and change it to [0.5 ~ 2.0]
public static var spriteScale:Number = 1.2;
//The bigger the value the slower the fade out speed is (the effect of the bitmap 'footsteps')
public static var multi :Number = 0.98;
public static var rotationSpeed:Number = 3;
public static var LineThikness:Number = 30;
//Arc length 1 - 360
public static var ArcLength:Number = 60;
//BlurX and BlurY
public static var blurSize:Number = 10;
//Try and set blur alpha to 1.
public static var blurAlpha:Number = .2;
public static var blurStrength:Number = 6;
//Dont touch this vars.
public static var redOffset :Number = 0.00;
public static var greenOffset :Number = 0.00;
public static var blueOffset :Number = 0.00;
public static var alphaOffset :Number = 1.00;
public static var redMulti :Number = multi;
public static var greenMulti :Number = multi;
public static var blueMulti :Number = multi;
public static var alphaMulti :Number = 1.00;
}
class MyMain extends Sprite
{
private var nextColor:int = 0;
private var color:int = 0;
private var s:Sprite;
private var stg:Stage;
public function MyMain()
{
s = new Sprite();
addChild(s);
s.scaleX = s.scaleY = Vars.spriteScale;
s.x = s.y = 465 / 2;
}
public function draw():void
{
fixColor();
s.graphics.clear();
s.graphics.lineStyle(Vars.LineThikness,0xFFFFFF);
//drawArc(target:Graphics, radius, arc, startAngle, yRadius, lineTo ? Boolean)
drawArc(s.graphics, 80, Vars.ArcLength, nextColor,0,false);
}
private function fixColor():void
{
//s.x = parent.mouseX;
nextColor = Vars.rotationSpeed + nextColor;
nextColor = fix(nextColor,0,360);
color = new ColorHSV(nextColor, 1, 1).toRGB().value
filters = [new GlowFilter(
color
,Vars.blurAlpha // Alpha
,Vars.blurSize // BlurX
,Vars.blurSize // BlurY
,Vars.blurStrength // Strength
,3 // Quality
)];
trace(nextColor);
}
}
/* ***********************
MATH FUNCITONS
**********************/
//new abs function, about 25x faster than Math.abs
function abs(value:Number):Number
{
return value < 0 ? -value : value;
}
//new ceil function about 75% faster than Math.ceil.
function ceil(value:Number):Number
{
return (value % 1) ? int(value) + 1 : value;
}
//Get the number sign (fast) !dont use zero's on this function
function sign(value:Number):int
{
return value < 0 ? -1 : 1;
}
//Quick max
function max(value1:Number,value2:Number):Number
{
return value1 > value2 ? value1 : value2;
}
//Quick min
function min(value1:Number,value2:Number):Number
{
return value1 < value2 ? value1 : value2;
}
//Fix number in between a range of [min,max]
function range(value:Number,min:Number = 0,max:Number = 1):Number
{
return (value < min ? min : (value > max ? max : value));
}
//Fix number in between a range of [min,max] , if bigger then max move to min and add extra and vise versa.
function fix(value:Number,min:Number = 0, max:Number = 1):Number
{
var x:Number = max - min;
while(value > max) value -= x;
while(value < min) value += x;
return value;
}
//Quick random value
function rnd(value:Number = 0 ,noZero:Boolean = false):Number
{
if(value == 0) return Math.random();
return Math.random() * value + (noZero ? 1 : 0);
}
//Random number between min and max
function rndRange(min:Number,max:Number):Number
{
return rnd() * (max - min) + min;
}
//Quick random sign
function rndSign():int
{
return sign(rnd() - .5);
}
//Quick random boolean.
function rndBool():Boolean
{
return Math.random() > .5;
}
// DRAW ARC FUNCTION / DRAW CIRCLE SEGMENT.
//Function source : http://icodesnip.com/snippet/actionscript-3/as3-drawing-shapes-arc-burst-dashed-line-gear-polygon-star-wedge-line
function drawArc(target:Graphics, radius:Number, arc:Number, startAngle:Number=0, yRadius:Number=0, lineTo:Boolean = false):void
{
if (startAngle == 0)startAngle = 0; if (yRadius == 0)yRadius = radius; if (abs(arc) > 360)arc = 360;
var segAngle:Number, theta:Number, angle:Number, angleMid:Number, segs:Number, ax:Number, ay:Number, bx:Number, by:Number, cx:Number, cy:Number;
segs = ceil(abs(arc) / 45);segAngle = arc / segs;theta = -(segAngle / 180) * Math.PI;angle = -(startAngle / 180) * Math.PI;
if (segs > 0)
{
lineTo ? target.lineTo(Math.cos(angle) * radius, Math.sin(angle) * yRadius) :
target.moveTo(Math.cos(angle) * radius, Math.sin(angle) * yRadius);
for (var i:int = 0; i < segs; ++i)
{
angle += theta; angleMid = angle - (theta / 2);
bx = Math.cos(angle) * radius; by = Math.sin(angle) * yRadius;
cx = Math.cos(angleMid) * (radius / Math.cos(theta / 2)); cy = Math.sin(angleMid) * (yRadius / Math.cos(theta / 2));
target.curveTo(cx, cy, bx, by);
}
}
}
class Main extends Sprite
{
private var cont:Container;
private var keyL:Boolean;
private var keyR:Boolean;
public function Main()
{
addEventListener(Event.ADDED_TO_STAGE,init);} private function init(e:Event):void {removeEventListener(Event.ADDED_TO_STAGE,init);
inittrace(stage);
//var stats:Stats = new Stats();
//addChild(stats);
//stats.x = stage.stageWidth - stats.width;
//stats.y = stage.stageHeight - stats.height;
//stage.frameRate = 60;
cont = new Container();
addChild(cont);
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKD);
stage.addEventListener(KeyboardEvent.KEY_UP,onKU);
this.addEventListener(Event.ENTER_FRAME,loop);
}
private function onKU(e:KeyboardEvent):void
{
keyR = (!(e.keyCode == 39 || e.keyCode == 68) && keyR);
keyL = (!(e.keyCode == 37 || e.keyCode == 65) && keyL);
}
private function onKD(e:KeyboardEvent):void
{
keyR = (e.keyCode == 39 || e.keyCode == 68);
keyL = (e.keyCode == 37 || e.keyCode == 65);
}
private function loop(e:Event):void
{
//if(keyL) game.rotate(-_wheelRotationSpeedOnKeyDown);
//if(keyR) game.rotate(_wheelRotationSpeedOnKeyDown);
}
}
class Container extends Sprite
{
private var main:MyMain;
private var s:ShadowSprite;
public function Container()
{
s = new ShadowSprite(465,465);
addChild(s);
main = new MyMain();
s.s.addChild(main);
addEventListener(Event.ENTER_FRAME,draw);
}
private function draw(e:Event):void
{
main.draw();
s.fade();
}
}
class ShadowSprite extends Sprite
{
public var bmp:Bitmap;
public var bmpdata:BitmapData;
public var drawMe:Sprite;
public function ShadowSprite(w:Number,h:Number)
{
bmpdata = new BitmapData(w, h,false,0);
bmp = new Bitmap(bmpdata);
addChild(bmp);
drawMe = new Sprite();
}
public function get g():Graphics
{
return drawMe.graphics;
}
public function get s():Sprite
{
return drawMe;
}
public function fade():void
{
var result:Sprite = new Sprite();
result.addChild(bmp);
bmp.transform.colorTransform = new ColorTransform(
Vars.redMulti,
Vars.greenMulti,
Vars.blueMulti,
Vars.alphaMulti,
Vars.redOffset,
Vars.greenOffset,
Vars.blueOffset,
Vars.alphaOffset
);
result.addChild(drawMe);
bmpdata.draw(result);
addChild(bmp);
bmp.transform.colorTransform = new ColorTransform();
}
}
/*
__/\\\\\\\\\\\\\\\____/\\\\\\\\\_________/\\\\\\\\\___________/\\\\\\\\\__/\\\\\\\\\\\\\\\_
_\///////\\\/////___/\\\///////\\\_____/\\\\\\\\\\\\\______/\\\////////__\/\\\///////////__
_______\/\\\_______\/\\\_____\/\\\____/\\\/////////\\\___/\\\/___________\/\\\_____________
_______\/\\\_______\/\\\\\\\\\\\/____\/\\\_______\/\\\__/\\\_____________\/\\\\\\\\\\\_____
_______\/\\\_______\/\\\//////\\\____\/\\\\\\\\\\\\\\\_\/\\\_____________\/\\\///////______
_______\/\\\_______\/\\\____\//\\\___\/\\\/////////\\\_\//\\\____________\/\\\_____________
_______\/\\\_______\/\\\_____\//\\\__\/\\\_______\/\\\__\///\\\__________\/\\\_____________
_______\/\\\_______\/\\\______\//\\\_\/\\\_______\/\\\____\////\\\\\\\\\_\/\\\\\\\\\\\\\\\_
_______\///________\///________\///__\///________\///________\/////////__\///////////////__
*/
import flash.text.TextField;
import flash.text.TextFormat;
///// WONDERFL TRACE /////
function inittrace(s:Stage):void{WTrace.initTrace(s);}var trace:Function;class WTrace{
private static var FONT:String = "_sans";
private static var SIZE:Number = 24;
private static var SPACE:String = " ";
private static var COLOR:uint = 0xFFFFFF;
private static var LINES:uint = 2;
private static var TextFields:Array = [];
private static var trace_stage:Stage;
public static function initTrace(stg:Stage):void{trace_stage = stg;trace = wtrace;}
private static function scrollup():void{if (TextFields.length > LINES){
var removeme:TextField = TextFields.shift();
trace_stage.removeChild(removeme);removeme = null;
}
for(var x:Number=0;x<TextFields.length;x++){
(TextFields[x] as TextField).y -= SIZE*1.2;
}}
public static function wtrace(... args):void{var s:String="";var tracefield:TextField;
for (var i:int;i < args.length;i++){if (i != 0) s+=SPACE;s+=args[i].toString();}
tracefield= new TextField();tracefield.autoSize = "right";tracefield.textColor = COLOR;
tracefield.text = s;tracefield.y = trace_stage.stageHeight - 10;
var tf:TextFormat = new TextFormat(FONT, SIZE);tracefield.setTextFormat(tf);
trace_stage.addChild(tracefield);scrollup();TextFields.push(tracefield);}}