In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

ひよこちゃん 球体の上でゆららゆらら

//////////////////////////////////////////////////////////////////////////////
ひよこちゃん 球体の上でゆらゆら
//////////////////////////////////////////////////////////////////////////////
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/anXY
 */

// forked from ProjectNya's ひよこちゃん 球体の上でゆらゆら
////////////////////////////////////////////////////////////////////////////////
// ひよこちゃん 球体の上でゆらゆら
////////////////////////////////////////////////////////////////////////////////

package {

	import flash.display.Sprite;
	import flash.display.Shape;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.system.Security;
	import flash.display.BlendMode;

	[SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]

	public class Main extends Sprite {
		private static var basePath:String = "http://assets.wonderfl.net/images/related_images/";
		private static var sunshinePath:String = "9/9b/9bbe/9bbec77d53bddc5e7a5f2c00abbade6bd641c549";
		private var loader:PiyoLoader;
		private static var piyoPath:String = "http://www.project-nya.jp/images/flash/piyo.swf";
		private var piyo:MovieClip;
		private var water:Wave;
		private static var waves:Array = [190, 198, 206, 214];
		private static var segments:uint = 5;
		private static var xOffset:Number = 0.25;
		private static var yOffset:Number = 0.01;
		private var ball:Ball;
		private var angle:Number = 0;
		private static var distance:uint = 150;
		private static var radius:uint = 15;
		private static var radian:Number = Math.PI/180;
		private static var speed:uint = 3;

		public function Main() {
			//Wonderfl.disable_capture();
			Wonderfl.capture_delay(4);
			init();
		}

		private function init():void {
			var sky:Sky = new Sky(465, 350);
			addChild(sky);
			var ground:Ground = new Ground(465, 115);
			addChild(ground);
			ground.y = 350;
			var sun:Sun = new Sun(100);
			addChild(sun);
			sun.x = 10;
			sun.y = 10;
			var shine:PhotoLoader = new PhotoLoader();
			addChild(shine);
			shine.alpha = 0.5;
			shine.load(basePath + sunshinePath);
			var frame:Shape = new Shape();
			frame.graphics.beginFill(0xFFFFFF);
			frame.graphics.drawCircle(0, 0, 119);
			frame.graphics.endFill();
			frame.x = 150;
			frame.y = 120;
			water = new Wave(300, 240, 0.2, 0.4);
			water.x = -150;
			water.y = -120;
			water.blendMode = BlendMode.MULTIPLY;
			water.addChild(frame);
			water.mask = frame;
			water.initialize(waves, segments, xOffset, yOffset);
			water.start();
			ball = new Ball(0, 120, 0xFFFFFF);
			addChild(ball);
			ball.x = 232;
			ball.y = 400;
			ball.contain(water);
			ball.base.blendMode = BlendMode.OVERLAY;
			loader = new PiyoLoader();
			loader.addEventListener(PiyoLoader.COMPLETE, complete, false, 0, true);
			loader.load(piyoPath);
		}
		private function complete(evt:Event):void {
			loader.removeEventListener(PiyoLoader.COMPLETE, complete);
			piyo = loader.content;
			addChild(piyo);
			piyo.x = 232;
			piyo.y = 165;
			piyo.scaleX = piyo.scaleY = 2;
			piyo.shade.visible = false;
			loader = null;
			piyo.velocity = 0;
			piyo.angle = 0;
			addEventListener(Event.ENTER_FRAME, update, false, 0, true);
		}
		private function update(evt:Event):void {
			ball.x = piyo.x = 232 + distance*Math.sin(angle*radian);;
			angle += speed;
			piyo.piyo.rotation = piyo.velocity;
			piyo.velocity = radius*Math.sin(piyo.angle*radian);
			piyo.angle += speed;
		}

	}

}


import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.HTTPStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.system.Security;
import flash.system.LoaderContext;

class PiyoLoader extends Sprite {
	private var loader:Loader;
	private var info:LoaderInfo;
	public var content:MovieClip;
	public static const IO_ERROR:String = IOErrorEvent.IO_ERROR;
	public static const HTTP_STATUS:String = HTTPStatusEvent.HTTP_STATUS;
	public static const SECURITY_ERROR:String = SecurityErrorEvent.SECURITY_ERROR;
	public static const INIT:String = Event.INIT;
	public static const COMPLETE:String = Event.COMPLETE;

	public function PiyoLoader() {
		Security.allowDomain("www.project-nya.jp");
		loader = new Loader();
		info = loader.contentLoaderInfo;
	}

	public function load(file:String):void {
		info.addEventListener(IOErrorEvent.IO_ERROR, ioerror, false, 0, true);
		info.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpstatus, false, 0, true);
		info.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityerror, false, 0, true);
		info.addEventListener(Event.INIT, initialize, false, 0, true);
		info.addEventListener(Event.COMPLETE, complete, false, 0, true);
		try {
			loader.load(new URLRequest(file), new LoaderContext(true));
		} catch (err:Error) {
			trace(err.message);
		}
	}
	public function unload():void {
		loader.unload();
	}
	private function ioerror(evt:IOErrorEvent):void {
		loader.unload();
		dispatchEvent(new Event(PiyoLoader.IO_ERROR));
	}
	private function httpstatus(evt:HTTPStatusEvent):void {
		dispatchEvent(new Event(PiyoLoader.HTTP_STATUS));
	}
	private function securityerror(evt:SecurityErrorEvent):void {
		dispatchEvent(new Event(PiyoLoader.SECURITY_ERROR));
	}
	private function initialize(evt:Event):void {
		content = MovieClip(info.content);
		dispatchEvent(new Event(PiyoLoader.INIT));
	}
	private function complete(evt:Event):void {
		info.removeEventListener(IOErrorEvent.IO_ERROR, ioerror);
		info.removeEventListener(HTTPStatusEvent.HTTP_STATUS, httpstatus);
		info.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, securityerror);
		info.removeEventListener(Event.INIT, initialize);
		info.removeEventListener(Event.COMPLETE, complete);
		//addChild(loader);
		dispatchEvent(new Event(PiyoLoader.COMPLETE));
	}

}


import flash.display.Shape;
import flash.geom.Matrix;
import flash.display.GradientType;

class Sky extends Shape {
	private static var _width:uint;
	private static var _height:uint;
	private static var color1:uint = 0x3F68AB;
	private static var color2:uint = 0x77B2EE;

	public function Sky(w:uint, h:uint) {
		_width = w;
		_height = h;
		draw();
	}

	private function draw():void {
		var colors:Array = [color1, color2];
		var alphas:Array = [1, 1];
		var ratios:Array = [0, 255];
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox(_width, _height, 0.5*Math.PI, 0, 0);
		graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
		graphics.drawRect(0, 0, _width, _height);
		graphics.endFill();
	}

}


import flash.display.Shape;
import flash.geom.Matrix;
import flash.display.GradientType;

class Ground extends Shape {
	private static var _width:uint;
	private static var _height:uint;
	private static var color1:uint = 0x99CC33;
	private static var color2:uint = 0x7EB133;

	public function Ground(w:uint, h:uint) {
		_width = w;
		_height = h;
		draw();
	}

	private function draw():void {
		var colors:Array = [color1, color2];
		var alphas:Array = [1, 1];
		var ratios:Array = [0, 255];
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox(_width, _height, 0.5*Math.PI, 0, 0);
		graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
		graphics.drawRect(0, 0, _width, _height);
		graphics.endFill();
	}

}


import flash.display.Shape;
import flash.geom.Matrix;
import flash.display.GradientType;

class Sun extends Shape {
	private static var radius:uint;
	private static var color:uint = 0xFFFFFF;

	public function Sun(r:uint) {
		radius = r;
		draw();
	}

	private function draw():void {
		var colors:Array = [color, color, color];
		var alphas:Array = [1, 0.3, 0];
		var ratios:Array = [25, 102, 231];
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox(radius*2, radius*2, 0, -radius, -radius);
		graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, matrix);
		graphics.drawCircle(0, 0, radius);
		graphics.endFill();
	}

}


import flash.display.Sprite;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.HTTPStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.display.Bitmap;
import flash.system.LoaderContext;

class PhotoLoader extends Sprite {
	private var loader:Loader;
	private var info:LoaderInfo;
	public var content:Bitmap;
	private var smoothing:Boolean;
	public static const IO_ERROR:String = IOErrorEvent.IO_ERROR;
	public static const HTTP_STATUS:String = HTTPStatusEvent.HTTP_STATUS;
	public static const SECURITY_ERROR:String = SecurityErrorEvent.SECURITY_ERROR;
	public static const INIT:String = Event.INIT;
	public static const COMPLETE:String = Event.COMPLETE;

	public function PhotoLoader() {
		loader = new Loader();
		info = loader.contentLoaderInfo;
	}

	public function load(file:String, s:Boolean = false):void {
		smoothing = s;
		info.addEventListener(IOErrorEvent.IO_ERROR, ioerror, false, 0, true);
		info.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpstatus, false, 0, true);
		info.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityerror, false, 0, true);
		info.addEventListener(Event.INIT, initialize, false, 0, true);
		info.addEventListener(Event.COMPLETE, complete, false, 0, true);
		try {
			loader.load(new URLRequest(file), new LoaderContext(true));
		} catch (err:Error) {
			trace(err.message);
		}
	}
	public function unload():void {
		loader.unload();
	}
	private function ioerror(evt:IOErrorEvent):void {
		loader.unload();
		dispatchEvent(new Event(PhotoLoader.IO_ERROR));
	}
	private function httpstatus(evt:HTTPStatusEvent):void {
		dispatchEvent(new Event(PhotoLoader.HTTP_STATUS));
	}
	private function securityerror(evt:SecurityErrorEvent):void {
		dispatchEvent(new Event(PhotoLoader.SECURITY_ERROR));
	}
	private function initialize(evt:Event):void {
		content = Bitmap(info.content);
		if (smoothing) content.smoothing = true;
		dispatchEvent(new Event(PhotoLoader.INIT));
	}
	private function complete(evt:Event):void {
		info.removeEventListener(IOErrorEvent.IO_ERROR, ioerror);
		info.removeEventListener(HTTPStatusEvent.HTTP_STATUS, httpstatus);
		info.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, securityerror);
		info.removeEventListener(Event.INIT, initialize);
		info.removeEventListener(Event.COMPLETE, complete);
		addChild(loader);
		dispatchEvent(new Event(PhotoLoader.COMPLETE));
	}

}


import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
import frocessing.math.PerlinNoise;
import frocessing.color.ColorHSV;
//import org.libspark.utils.GeomUtil;

class Wave extends Sprite {
	private var canvas:Sprite;
	private var perlin:PerlinNoise;
	private var color:ColorHSV;
	private var t:Number = 0;
	private var bWidth:uint;
	private var bHeight:uint;
	private var top:Number = 0.2;
	private var bottom:Number = 0.6;
	private var amplitude:Number = bottom - top;
	private var waves:Array = [190, 198, 206, 214];
	private var segments:uint = 5;
	private var ratio:Number = 1/segments;
	private var xOffset:Number = 0.25;
	private var yOffset:Number = 0.01;
	private static var tightness:uint = 40;

	public function Wave(w:uint, h:uint, t:Number = 0.2, b:Number = 0.6) {
		bWidth = w;
		bHeight = h;
		top = t;
		bottom = b;
		amplitude = bottom - top;
		init();
	}

	private function init():void {
		canvas = new Sprite();
		addChild(canvas);
		perlin = new PerlinNoise();
		color = new ColorHSV();
	}
	public function initialize(w:Array = null, s:uint = 5, xo:Number = 0.25, yo:Number = 0.01):void {
		waves = w;
		if (waves == null) waves = [190, 198, 206, 214];
		segments = s;
		xOffset = xo;
		yOffset = yo;
		ratio = 1/segments;
	}
	public function start():void {
		addEventListener(Event.ENTER_FRAME, draw, false, 0, true);
	}
	public function stop():void {
		removeEventListener(Event.ENTER_FRAME, draw);
	}
	private function draw(evt:Event):void {
		canvas.graphics.clear();
		for (var d:uint = 0; d < waves.length; d++) {
			var points:Array = new Array();
			points.push(new Point(-bWidth*ratio, bHeight*amplitude));
			for (var n:uint = 1; n <= segments+1; n++) {
				var xPos:Number = n*bWidth*ratio;
				var yPos:Number = perlin.noise(n*xOffset*d, t)*bHeight*amplitude + bHeight*top;
				points.push(new Point(xPos-bWidth*ratio, yPos));
			}
			t += yOffset;
			points.push(new Point(bWidth*(1+ratio), bHeight*amplitude));
			points.unshift(points[0]);
			points.push(points[points.length-1]);
			color.h = waves[d];
			canvas.graphics.beginFill(color.value, 0.2);
			canvas.graphics.moveTo(points[0].x, points[0].y);
			for (var p:uint = 0; p < points.length-3; p++) {
				var p0:Point = points[p];
				var p1:Point = points[p+1];
				var p2:Point = points[p+2];
				var p3:Point = points[p+3];
				for (var s:uint = 1; s < tightness+1; s++) {
					//var px:Number = GeomUtil.spline(p0.x, p1.x, p2.x, p3.x, s/tightness);
					//var py:Number = GeomUtil.spline(p0.y, p1.y, p2.y, p3.y, s/tightness);
					var px:Number = spline(p0.x, p1.x, p2.x, p3.x, s/tightness);
					var py:Number = spline(p0.y, p1.y, p2.y, p3.y, s/tightness);
					canvas.graphics.lineTo(px, py);
				}
			}
			canvas.graphics.lineTo(bWidth*(1+ratio), bHeight);
			canvas.graphics.lineTo(-bWidth*ratio, bHeight);
			canvas.graphics.endFill();
		}
	}
	private function spline(p0:Number, p1:Number, p2:Number, p3:Number, t:Number):Number {
 		var v0:Number = (p2 - p0) * 0.5;
		var v1:Number = (p3 - p1) * 0.5;
		var t2:Number = t * t;
		var t3:Number = t2 * t;
		return (2 * p1 - 2 * p2 + v0 + v1) * t3 + ( -3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
	}

}


import flash.display.Sprite;
import flash.display.Shape;
import flash.display.DisplayObject;
import flash.filters.DropShadowFilter;
import flash.filters.GlowFilter;
import flash.geom.Matrix;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.InterpolationMethod;
import frocessing.color.ColorHSV;

class Ball extends Sprite {
	public var id:uint;
	private var radius:uint;
	private var color:uint;
	private var hsv:ColorHSV;
	private var ball:Sprite;
	public var base:Shape;
	private var inside:Sprite;
	private var light:Shape;
	private var shade:Shape;
	private static var bColor:uint = 0xFFFFFF;
	private static var sColor:uint = 0x000000;
	private var shaded:Boolean;
	private static var shadeHeight:Number;

	public function Ball(n:uint, r:uint, c:uint, a:Number = 1, s:Boolean = true) {
		id = n;
		radius = r;
		shaded = s;
		color = c;
		hsv = new ColorHSV(0, 1, 1);
		hsv.value = color;
		draw();
		ball.alpha = a;
		shadeHeight = radius*5;
	}

	public function init(hue:uint):void {
		hsv.h = hue;
		color = hsv.value;
		createBase();
	}
	public function contain(obj:DisplayObject):void {
		inside.addChild(obj);
	}
	public function set altitude(h:Number):void {
		ball.y = -radius-h;
		shade.alpha = 1 - h/shadeHeight;
	}
	private function draw():void {
		if (shaded) {
			shade = new Shape();
			addChild(shade);
			createShade();
		}
		ball = new Sprite();
		addChild(ball);
		ball.y = -radius;
		base = new Shape();
		ball.addChild(base);
		inside = new Sprite();
		ball.addChild(inside);
		light = new Shape();
		ball.addChild(light);
		createBase();
		createLight();
	}
	private function createBase():void {
		base.graphics.clear();
		base.graphics.beginFill(color);
		base.graphics.drawCircle(0, 0, radius);
		base.graphics.endFill();
		hsv.v = 0.8;
		var darken:uint = hsv.value;
		var glow:GlowFilter = new GlowFilter(darken, 1, radius*0.5, radius*0.5, 2, 3, true, false);
		base.filters = [glow];
	}
	private function createLight():void {
		var colors:Array = [bColor, bColor];
		var alphas:Array = [0.7, 0];
		var ratios:Array = [0, 191];
		var matrix:Matrix = new Matrix();
		var w:Number = radius*1.44;
		var h:Number = radius*1.35;
		var yOffset:Number = radius*0.95;
		matrix.createGradientBox(w, h, 0.5*Math.PI, -w*0.5, -yOffset);
		light.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
		light.graphics.drawEllipse(-w*0.5, -yOffset, w, h);
		light.graphics.endFill();
	}
	private function createShade():void {
		shade.graphics.beginFill(sColor);
		shade.graphics.drawEllipse(-radius*0.75, -radius*0.1775, radius*1.5, radius*0.375);
		shade.graphics.endFill();
		var shadow:DropShadowFilter = new DropShadowFilter(0, 90, sColor, 0.5, radius*0.15, radius*0.15, 1, 3, false, false, true);
		shade.filters = [shadow];
	}

}