Watching the Clouds
They're different every time.
/**
* Copyright royi ( http://wonderfl.net/user/royi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/mphM
*/
package {
import flash.events.MouseEvent;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.ColorTransform;
import flash.utils.getTimer;
import flash.events.Event;
import flash.display.Sprite;
[SWF(width=465, height=465, frameRate=60, backgroundColor=0x000000)]
public class Main extends Sprite {
private static const SQUARES:int = 28;
private var sw:Number = stage.stageWidth,
sh:Number = stage.stageHeight;
private var centerX:Number, centerY:Number;
private var board:Sprite = new Sprite();
private var squares:Array = [];
private var noise:BitmapData;
private var noisePos:int = 0;
private var mouseOver:Boolean = false;
public function Main() {
centerX = sw / 2;
centerY = sh / 2;
graphics.beginFill(0x000000);
graphics.drawRect(0, 0, sw, sh);
graphics.endFill();
addChild(board);
board.x = centerX;
board.y = centerY;
noise = new BitmapData(SQUARES * 30, SQUARES, false, 0x000000);
noise.perlinNoise(SQUARES * 30, SQUARES, 30, Math.random() * 1000, true, true, 4);
var squareWidth:Number = sw / SQUARES;
var squareHeight:Number = sh / SQUARES;
for (var x:int = 0; x < SQUARES; x++) {
squares[x] = [];
for (var y:int = 0; y < SQUARES; y++) {
var square:Sprite = new Sprite();
square.graphics.beginFill(0x999999);
square.graphics.drawRect(-(squareWidth * .5), -(squareHeight * .5), squareWidth, squareHeight);
square.graphics.endFill();
square.x = x * squareWidth + (squareWidth * .5) - centerX;
square.y = y * squareHeight + (squareWidth * .5) - centerY;
square.z = Math.random() * 20;
squares[x][y] = square;
board.addChild(square);
}
}
addEventListener(Event.ENTER_FRAME, loop);
stage.addEventListener(Event.MOUSE_LEAVE, onMouseLeave);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onMouseLeave(e:Event):void { mouseOver = false; }
private function onMouseMove(e:MouseEvent):void { mouseOver = true; }
private function loop(e:Event):void {
var t:int = getTimer();
if (mouseOver) {
board.rotationX = -(centerY - mouseY) * .3;
board.rotationY = (centerX - mouseX) * .1;
} else {
board.rotationX = Math.sin(t*.005)*2;
board.rotationY = Math.cos(t*.005)*2;
}
var colorTransform:ColorTransform;
var rgb:uint, blue:uint;
for (var x:int = 0; x < SQUARES; x++) {
for (var y:int = 0; y < SQUARES; y++) {
rgb = noise.getPixel((x + noisePos) % noise.width, y);
blue = (rgb & 0xff);
squares[x][y].z = (blue * 2) - 100;
squares[x][y].rotationZ = blue+45;
colorTransform = new ColorTransform(1, 1, 1, 1, Math.cos(blue*.1)*255, Math.cos(blue*.01)*255, Math.sin(blue*.01)*255);
squares[x][y].transform.colorTransform = colorTransform;
}
}
noisePos++;
if (noisePos > noise.width) noisePos = 0;
}
}
}