Pink Blob
// forked from AceDecade's Dynamic Outline
package{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.text.TextField;
import flash.utils.getTimer;
public class FlashTest extends Sprite{
public var circles:Number = 30;
public var maxx:Number = 50;
public var maxy:Number = 50;
public var maxsize:Number = 30;
public var minsize:Number = 10;
public var maxspeed:Number = 1;
public static const DEG_RAD:Number = Math.PI/180;
public var timer:Number = 0;
public var acceleration:Number = 5;
public var steps:Number = 180;
public var validity:Number = 1;
public var cloudcolor:uint = 0xffcccc;
public var linewidth:Number = 3;
public var easydraw:Boolean = false;
public var cloud:Sprite = new Sprite();
public var face:Sprite = new Sprite();
public var Circles:Vector.<Vector.<Number>> = new Vector.<Vector.<Number>>();
public var fps:TextField = new TextField();
public function FlashTest(){
scaleX = 2;
scaleY = 2;
addChild(cloud);
addChild(face);
with(face.graphics){
clear();
lineStyle(2,0x000000,1);
moveTo(28.7,1.8);
curveTo(42,10,-27.25,7.05);
beginFill(0x990000);
moveTo(-27.25,7.05);
curveTo(-23,30.75,0,31.45);
curveTo(23,30.75,25.15,7.3);
endFill();
beginFill(0xff99cc);
moveTo(8.3,29.9);
curveTo(10,18.75,-4.75,18.5);
curveTo(-18.5,18.5,-18.25,24.9);
curveTo(-7,34,8.3,29.9);
endFill();
moveTo(-23.95,-3.45);
curveTo(-14.95,-8.15,-3.95,-3.45);
beginFill(0xffffff);
moveTo(-18.85,-5.8);
curveTo(-27.5,-28.5,-14.65,-29.4);
curveTo(0,-28.5,-10.85,-5.8);
endFill();
beginFill(0x000000);
drawEllipse(-14.95,-25.45,7,14);
endFill();
moveTo(6.05,-3.45);
curveTo(15.05,-8.15,26.05,-3.45);
beginFill(0xffffff);
moveTo(11.15,-5.8);
curveTo(-27.5+30,-28.5,15.35,-29.4);
curveTo(30,-28.5,19.15,-5.8);
endFill();
beginFill(0x000000);
drawEllipse(15.05,-25.45,7,14);
endFill();
}
addChild(fps);
fps.x = -stage.stageWidth/4;
fps.y = -stage.stageHeight/4;
fps.height = 15;
fps.width = 50;
steps = 360/steps;
stage.addEventListener(Event.ENTER_FRAME,main);
stage.addEventListener(MouseEvent.MOUSE_DOWN,mousedown);
x = stage.stageWidth/2;
y = stage.stageHeight/2;
init();
}
public function init():void{
var v:Vector.<Number> = new Vector.<Number>();
v.push(0,0,40,1600,0,0);
Circles.push(v);
for(var i:int=0;i<circles;i++){
var W:Number = range(maxx,-maxx);
var H:Number = range(maxy,-maxy);
var S:Number = range(maxsize,minsize);
var V:Vector.<Number> = new Vector.<Number>();
V.push(W,H,S,Math.pow(S,2),0,0);
Circles.push(V);
}
}
public function main(e:Event):void{
var d:Number = getTimer();
fps.text = Math.round(1000/(d-timer)).toString()+" fps";
timer = d;
cloud.graphics.clear();
for(var i:int=0;i<circles;i++){
var a:Vector.<Number> = Circles[i];
if(a[0] > 0){
a[4] -= acceleration/a[2];
}else if(a[0] < 0){
a[4] += acceleration/a[2];
}
if(a[1] > 0){
a[5] -= acceleration/a[2];
}else if(a[1] < 0){
a[5] += acceleration/a[2];
}
a[0] += a[4];
a[1] += a[5];
if(a[0]+a[2] > stage.stageWidth/2){
a[0] = stage.stageWidth/2-a[2];
a[4] = -a[4];
}else if(a[0]-a[2] < -stage.stageWidth/2){
a[0] = -stage.stageWidth/2+a[2];
a[4] = -a[4];
}
if(a[1]+a[2] > stage.stageHeight/2){
a[1] = stage.stageHeight/2-a[2];
a[5] = -a[5];
}else if(a[1]-a[2] < -stage.stageHeight/2){
a[1] = -stage.stageHeight/2+a[2];
a[5] = -a[5];
}
}
render();
}
public function render():void{
for(var i:int=0;i<circles;i++){
with(cloud.graphics){
lineStyle(0,0x000000,0);
beginFill(cloudcolor);
drawCircle(Circles[i][0],Circles[i][1],Circles[i][2]);
endFill();
lineStyle(linewidth,0x000000,1);
}
var dx:Number=0;
var dy:Number=0;
var mark:Boolean = false;
for(var j:Number=0;j<=360;j+=steps){
var X:Number = Circles[i][0]+Math.cos(j*DEG_RAD)*(Circles[i][2]+validity);
var Y:Number = Circles[i][1]+Math.sin(j*DEG_RAD)*(Circles[i][2]+validity);
var h:Boolean = false;
for(var k:int=0;k<circles;k++){
var d:Number = Math.pow(X-Circles[k][0],2)+Math.pow(Y-Circles[k][1],2);
if(d < Circles[k][3]){
k = circles;
h = true;
}
}
if(!h){
if(easydraw){
X = Circles[i][0]+Math.cos(j*DEG_RAD)*Circles[i][2];
Y = Circles[i][1]+Math.sin(j*DEG_RAD)*Circles[i][2];
with(cloud.graphics){
drawCircle(X,Y,1);
}
}else{
if(mark){
cloud.graphics.moveTo(dx,dy);
dx = X;
dy = Y;
cloud.graphics.lineTo(dx,dy);
}else{
dx = X;
dy = Y;
mark = true;
}
}
}else{
mark = false;
}
}
}
}
public function mousedown(e:MouseEvent):void{
reset();
render();
}
public function reset():void{
cloud.graphics.clear();
Circles = new Vector.<Vector.<Number>>();
init();
}
public function range(M:Number,m:Number=0):Number{
return Math.random()*(M-m)+m;
}
}
}