モンドリアン風味
/**
* Copyright kenji_special ( http://wonderfl.net/user/kenji_special )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9rZk
*/
package {
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
[SWF(backgroundColor="0", width="465", height="465")]
public class FlashTest extends Sprite {
private var base:Sprite = new Sprite();
private const W:int = 400;
private var spRex:Array = new Array();
private var lineWArr:Array = new Array();
private var lineHArr:Array = new Array();
private var speedArr:Array =new Array();
private var RecArray:Array = new Array();
private var RedRecArrayW:Array =new Array();
private var RedRecArrayH:Array =new Array();
private var SpeedW:Array =new Array();
private var SpeedH:Array =new Array();
public function FlashTest() {
base.graphics.beginFill(0xFAF7EF);
base.graphics.drawRect(0, 0, W, W);
base.graphics.endFill();
base.x = (stage.stageWidth - W)/2;
base.y = (stage.stageHeight - W)/2;
stage.addChild(base);
for(var i:int = 0; i<10; i++)
{
var lineW01:Sprite =new Sprite();
lineW01.graphics.beginFill(0xF6DE4F);
lineW01.graphics.drawRect(0, 0, 10, W);
lineW01.x =W * Math.random();
lineW01.y = 0;
lineWArr.push(lineW01);
base.addChild(lineW01);
var lineH01:Sprite = new Sprite();
lineH01.graphics.beginFill(0xF6DE4F);
lineH01.graphics.drawRect(0, 0, W, 10);
lineH01.x = 0;
lineH01.y = W * Math.random();
lineHArr.push(lineH01);
base.addChild(lineH01);
speedArr[i] = 6 * Math.random() -3;
}
for(i = 0; i < 10; i++)
{
spRex[i] = new Array();
for(var j:int =0; j < 10; j++)
{
var spRec:Shape = new Shape();
if((i*j % 2) ==0)
{
spRec.graphics.beginFill(0x2E2A86);
}else
{
spRec.graphics.beginFill(0xF1ECE1);
}
spRec.graphics.drawRect(0, 0, 10, 10);
spRec.graphics.endFill();
spRec.x = (lineWArr[i] as Sprite).x ;
spRec.y = (lineHArr[j] as Sprite).y;
base.addChild(spRec);
(spRex[i] as Array).push(spRec);
}
}
for(i = 0; i <10; i++)
{
RedRecArrayW[i] = new Array();
SpeedW[i] = new Array();
for(j =0; j < 10; j++)
{
spRec = new Shape();
spRec.graphics.beginFill(0xD51B1A);
spRec.graphics.drawRect(0, 0, 10, 10);
spRec.graphics.endFill();
spRec.x = 0;
spRec.y = (W-10) * Math.random();
SpeedW[i][j] = 8 * Math.random() - 4;
(RedRecArrayW[i] as Array).push(spRec);
(lineWArr[i] as Sprite).addChild(spRec);
}
}
for(i = 0; i <10; i++)
{
RedRecArrayH[i] = new Array();
SpeedH[i] =new Array();
for(j =0; j < 10; j++)
{
spRec = new Shape();
spRec.graphics.beginFill(0xD51B1A);
spRec.graphics.drawRect(0, 0, 10, 10);
spRec.graphics.endFill();
spRec.y = 0;
spRec.x = (W-10) * Math.random();
SpeedH[i][j] = 8 *Math.random() - 4;
(RedRecArrayH[i] as Array).push(spRec);
(lineHArr[i] as Sprite).addChild(spRec);
}
}
stage.addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(e:Event):void
{
for(var i:int = 0; i <10; i++)
{
(lineWArr[i] as Sprite).x += speedArr[i];
(lineHArr[i] as Sprite).y += speedArr[i];
if((lineWArr[i] as Sprite).x > 400 -10)
{
(lineWArr[i] as Sprite).x = 0;
}
if((lineWArr[i] as Sprite).x <0 )
{
(lineWArr[i] as Sprite).x = 400 -10;
}
if((lineHArr[i] as Sprite).y > 400 -10)
{
(lineHArr[i] as Sprite).y = 0;
}
if((lineHArr[i] as Sprite).y < 0 )
{
(lineHArr[i] as Sprite).y = 400 -10;
}
}
for(i = 0; i< 10; i++)
{
for(var j:int = 0; j < 10; j++)
{
(spRex[i][j] as Shape).graphics.drawRect(0, 0, 10, 10);
(spRex[i][j] as Shape).x = (lineWArr[i] as Sprite).x;
(spRex[i][j] as Shape).y = (lineHArr[j] as Sprite).y;
base.addChild(spRex[i][j]);
}
}
for(i = 0; i< 10; i++)
{
for(j = 0; j < 10; j++)
{
(RedRecArrayH[i][j] as Shape).x += SpeedH[i][j];
(RedRecArrayW[i][j] as Shape).y += SpeedW[i][j];
if((RedRecArrayH[i][j] as Shape).x < 0)
{
(RedRecArrayH[i][j] as Shape).x = 400 -10;
}
if((RedRecArrayH[i][j] as Shape).x > 400 -10)
{
(RedRecArrayH[i][j] as Shape).x = 0;
}
if((RedRecArrayW[i][j] as Shape).y < 0)
{
(RedRecArrayW[i][j] as Shape).y = 400 -10;
}
if((RedRecArrayW[i][j] as Shape).y > 400 -10)
{
(RedRecArrayW[i][j] as Shape).y = 0;
}
(lineWArr[i] as Sprite).addChild(RedRecArrayW[i][j]);
(lineHArr[i] as Sprite).addChild(RedRecArrayH[i][j]);
}
}
}
}
}