snake in my wine
/**
* Copyright tequibo ( http://wonderfl.net/user/tequibo )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/keNAL
*/
// forked from tequibo's Silly Circles
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.events.Event;
import flash.display.Sprite;
import flash.filters.*;
public class Chain extends Sprite {
private var gr:Sprite = new Sprite();
private var f:Number = 0;
private var r:Number = 200;
private var ticker:Timer = new Timer(500, 0);
private var arr:Array = new Array();
private var bg:Sprite = new Sprite();
private var iAmSoLazy:Sprite = new Sprite();
private var nodeW:Number = 8;
private var nodeH:Number = 8;
private var sillyBitmap:Bitmap;
private var sillyData:BitmapData = new BitmapData(500, 500, false, 0xff000000);
private var nodesQ:int = 200;
public function Chain(){
sillyBitmap = new Bitmap(sillyData);
sillyBitmap.filters = [new BlurFilter(11, 11, 5)]
addChild(gr);
gr.addChild(sillyBitmap);
gr.addEventListener(Event.ENTER_FRAME, onFrame);
ticker.addEventListener(TimerEvent.TIMER, onTick);
ticker.start()
for (var i:int = 0; i < nodesQ; i++){
var node:Node = new Node(nodeW, nodeH);
gr.addChild(node);
arr.push(node);
node.x = 250;
node.y = 250;
}
stage.addEventListener(MouseEvent.CLICK, stage_click);
}
private function stage_click(e:MouseEvent):void {
change();
}
public function onTick(e:TimerEvent):void {
for (var i:int = 0; i < nodesQ; i++){
var node:Node = arr[i];
node.r += Math.random() * 50 - 25
}
}
public function change():void {
for (var i:int = 0; i < nodesQ; i++){
var node:Node = arr[i];
node.r = 0;
}
}
public function onFrame(e:Event):void {
var prevNode:Node;
for (var i:int = 0; i < nodesQ; i++){
var node:Node = arr[i];
if (i > 0){
node.x = prevNode.x + Math.cos(prevNode.rotation / 360 * Math.PI * 2) * nodeW;
node.y = prevNode.y + Math.sin(prevNode.rotation / 360 * Math.PI * 2) * nodeW;
node.targetR += (node.r - node.targetR) / 11;
node.rotation = node.targetR + prevNode.rotation
}
prevNode = node;
}
sillyData.draw(gr);
}
}
}
import flash.filters.*;
import flash.display.*;
class Node extends Sprite {
public var r:Number = 0;
public var targetR:Number = 0;
public function Node(width:Number = 10, height:Number = 5){
var color:Number = 0xffffff * Math.random()
graphics.beginFill(color, 1);
graphics.drawRect(0, -height / 2, width, height)
}
}