forked from: Make Wave
I saw sea from that greentec's circles
/**
* Copyright wrotenodoc ( http://wonderfl.net/user/wrotenodoc )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gxvr
*/
// forked from greentec's Make Wave
package {
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
public class FlashTest extends Sprite {
public var _width:int = 465;
public var _height:int = 465;
public var numCircleWidth:int = 60;
public var numCircleHeight:int = 60;
public var circleArray:Array;
public var indices:Vector.<int>
public var switch1:Boolean = true;
private var _water:Shape
public function FlashTest() {
// write as3 code here..
stage.scaleMode = "noScale";
var shape:Shape;
shape = new Shape();
//shape.graphics.beginFill(0x69D2E7);
shape.graphics.beginFill(0x0);
shape.graphics.drawRect(0, 0, _width, _height);
shape.graphics.endFill();
addChild(shape);
_water = new Shape
addChild(_water)
var i:int;
var j:int;
var circle:Circle;
var xWidth:int = _width / (numCircleWidth - 2);
var yHeight:int = _height / (numCircleHeight - 2);
circleArray = [];
indices = new Vector.<int>;
var k:int = 0;
for (i = -1; i < numCircleHeight; i += 1)
{
for (j = -1; j < numCircleWidth; j += 1)
{
circle = new Circle(xWidth * 5 / 4, yHeight * 5 / 4, Math.sin((i + j) * 180 / Math.PI) * 7);
circle.x = j * xWidth + xWidth / 2;
circle.y = i * yHeight + yHeight / 2;
circle._zSeed = ((i+1) + (j+1)) % (numCircleHeight) + ((Math.random()-.5) * 28)
addChild(circle);
circleArray.push(circle);
if(j != numCircleWidth - 1 && i != numCircleHeight - 1){
indices.push(k, k+1, k+1+numCircleWidth);
indices.push(k+1, k+1+numCircleWidth, k+1+numCircleWidth+1);
}
k++;
}
}
_water.rotationX = -45
addEventListener(Event.ENTER_FRAME, onLoop);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}
private function onLoop(e:Event):void
{
var i:int;
var circle:Circle;
var len:int;
len = circleArray.length;
for (i = 0; i < len; i += 1)
{
circle = circleArray[i];
circle.move();
}
var g:Graphics = _water.graphics
g.clear()
var a:Circle, b:Circle, c:Circle
for(i=0; i<indices.length; i+=3){
a = circleArray[indices[i]]
b = circleArray[indices[i+1]]
c = circleArray[indices[i+2]]
g.beginFill(0x00bfff, (a.z+b.z+c.z)/3)
g.moveTo(a.xx, a.yy)
g.lineTo(b.xx, b.yy)
g.lineTo(c.xx, c.yy)
g.lineTo(a.xx, a.yy)
g.endFill()
}
}
public function onKeyDown(e:KeyboardEvent):void
{
switch1 = !switch1;
var i:int;
var circle:Circle;
var len:int;
len = circleArray.length;
for (i = 0; i < len; i += 1)
{
circle = circleArray[i];
circle.baseCircle.visible = switch1;
}
}
}
}
Class
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
/**
* ...
* @author ypc
*/
class Circle extends Sprite
{
public var baseCircle:Shape;
public var mover:Shape;
public var time:int;
public var radius:int;
public var color:uint = 0xffffff;
private var _z:Number = 0
public var _zSeed:int
public function Circle(w:int, h:int, time:int = 0)
{
this.radius = w / 2;
this.time = time;
baseCircle = new Shape();
baseCircle.graphics.lineStyle(0, color, 1);
baseCircle.graphics.drawCircle(0, 0, w / 2);
//addChild(baseCircle);
mover = new Shape();
mover.graphics.lineStyle(0, color, 1);
mover.graphics.beginFill(color);
mover.graphics.drawCircle(0, 0, w / 8);
mover.x = Math.cos(time * 6 * Math.PI / 180) * radius;
mover.y = Math.sin(time * 6 * Math.PI / 180) * radius;
//addChild(mover);
//_zSeed = Math.random() * 6.28
}
public function move():void
{
time += 1;
time %= 60;
mover.x = Math.cos(time * 6 * Math.PI / 180) * radius;
mover.y = Math.sin(time * 6 * Math.PI / 180) * radius;
_z = norm(Math.sin((_zSeed + time) * 6 * Math.PI / 180), -1,1, 0.5,1.0)
super.z = _z * -500
}
private function norm(x:Number, min:Number, max:Number, newMin:Number, newMax:Number):Number {
return newMin + (newMax-newMin)*(x-min)/(max-min)
}
public function get xx():Number { return x + mover.x }
public function get yy():Number { return y + mover.y }
public override function get z():Number { return _z }
}
}