むーぶ2
線にグラデーションつけてみた
/**
* Copyright Kihara ( http://wonderfl.net/user/Kihara )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/yqTj
*/
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.GradientType;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.filters.GlowFilter;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
//[SWF(width="500", height="500" , backgroundColor="0")]
[SWF(width = "465",height = "465",frameRate = "40",backgroundColor = "0")]
public class flasn_ex3_5 extends Sprite
{
private var data:Array=[];
private var N:uint=30;
private var g:Graphics;
private var sp:Sprite;
private var line_al:Number;
private var line_N:Number=65;
public function flasn_ex3_5()
{
//ウィンドウのサイズが変わってもFlashのサイズを変えない
stage.scaleMode = StageScaleMode.NO_SCALE;
//原点をちゃんと左上にする
stage.align = StageAlign.TOP_LEFT;
var canvas:Sprite=new Sprite();
sp=new Sprite();
g=sp.graphics;
for(var i:int=0;i<N;i++){
var graph:Graph=new Graph(Math.random()*6+3,0,0,Math.random()*40+10,Math.random()*0xFFFFFF);
graph.x=Math.random()*stage.stageWidth;
graph.y=Math.random()*stage.stageHeight;
graph.vx=Math.random()*6-3;
graph.vy=Math.random()*6-3;
graph.vr=Math.random()*6-3;
//graph.filters=[new GlowFilter(0xFFFFFF*Math.random(),1,4,4,3),new BlurFilter(2,2)];
//graph.blendMode=BlendMode.ADD;
data.push(graph);
sp.addChild(data[i]);
}
addChild(sp);
//trace(stage.width,stage.height);
//trace(stage.stageWidth,stage.stageHeight);
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
public function spring(g1:Graph,g2:Graph):void{
var d:Number,ax:Number,ay:Number,ar:Number,k:Number=0.006;
var t1:Number=g1.rotation*Math.PI/180;
var t2:Number=g2.rotation*Math.PI/180;
var flag:Boolean=false;
var color:Number=0xFFFFFF;
for(var i:int=0;i<g1.n;i++){
for(var j:int=0;j<g2.n;j++){
var g1_x:Number=g1.x+g1.r2*Math.cos(g1.points_x[i]+t1);
var g1_y:Number=g1.y+g1.r2*Math.sin(g1.points_y[i]+t1);
var g2_x:Number=g2.x+g2.r2*Math.cos(g2.points_x[j]+t2);
var g2_y:Number=g2.y+g2.r2*Math.sin(g2.points_y[j]+t2);
var dx:Number=g1_x-g2_x,dy:Number=g1_y-g2_y;
d=Math.sqrt(dx*dx+dy*dy);
if(d<line_N){
line_al=1-(d/line_N);
g.lineStyle(1);
var m:Matrix=new Matrix();
m.createGradientBox(Math.abs(dx),Math.abs(dy),Math.atan2(dy,dx),Math.min(g1_x,g2_x),Math.min(g1_y,g2_y));
g.lineGradientStyle(GradientType.LINEAR,[g2.c2,g1.c2],[line_al,line_al],[0,255],m);
//graphics.lineStyle(1,g1.c2,1-(d/60));
g.moveTo(g1_x,g1_y);
g.lineTo(g2_x,g2_y);
flag=true;
}
}
}
if(flag){
ar=(g1.vr-g2.vr)*k;
ax=(g1.x-g2.x)*k;
ay=(g1.y-g2.y)*k;
//g1.al+=0.2;
g1.vr+=ar/g1.r2;
g1.vx+=ax/g1.r2;
g1.vy+=ay/g1.r2;
g2.vr+=-ar/g2.r2;
g2.vx+=-ax/g2.r2;
g2.vy+=-ay/g2.r2;
//g2.al+=0.2;
}
}
public function onEnterFrame(e:Event):void{
g.clear();
for(var s:int=0;s<N-1;s++){
for(var t:int=s+1;t<N;t++){
spring(data[s],data[t]);
}
}
for(var i:int=0;i<data.length;i++){
data[i].move();
if(data[i].x< -data[i].r2){
data[i].x=stage.stageWidth+data[i].r2;
}
if(data[i].x>stage.stageWidth+data[i].r2){
data[i].x= -data[i].r2;
}
if(data[i].y< -data[i].r2){
data[i].y=stage.stageHeight+data[i].r2;
}
if(data[i].y>stage.stageHeight+data[i].r2){
data[i].y= -data[i].r2;
}
}
}
}
}
import flash.display.Sprite;
class Graph extends Sprite{
public var al:Number;
public var vx:Number;
public var vy:Number;
public var vr:Number;
public var r2:Number;
public var n:int;
public var points_x:Array=[];
public var points_y:Array=[];
public var c2:Number;
private function bou(num:int,line:int,cc:Number,xx:int,yy:int):void{
var odd:Array=[];
var even:Array=[];
for(var i:int=0;i<num;i++){
var theta:Number=i*(2*Math.PI/num);
get_points(theta);
if(i%2==0)
even.push(theta);
else if(i%2==1)
odd.push(theta);
}
graphics.lineStyle(line,cc);
if(num%2==0){
graphics.moveTo(r2*Math.cos(even[0])+xx,r2*Math.sin(even[0])+yy);
for(var k:int=even.length-1;k>=0;k--){
graphics.lineTo(r2*Math.cos(even[k])+xx,r2*Math.sin(even[k])+yy);
}
graphics.moveTo(r2*Math.cos(odd[0])+xx,r2*Math.sin(odd[0]));
for(k=odd.length-1;k>=0;k--){
graphics.lineTo(r2*Math.cos(odd[k])+xx,r2*Math.sin(odd[k])+yy);
}
}
else if(num%2==1){
var arrays:Array=even.concat(odd);
graphics.moveTo(r2*Math.cos(arrays[0])+xx,r2*Math.sin(arrays[0])+yy);
for(var n:int=arrays.length-1;n>=0;n--)
graphics.lineTo(r2*Math.cos(arrays[n])+xx,r2*Math.sin(arrays[n])+yy);
}
}
private function get_points(t:Number):void{
points_x.push(t);
points_y.push(t);
}
public function Graph(num:int,_x:Number,_y:Number,r:Number,color:Number){
al=0;
vx=_x;
vy=_y;
r2=r;
c2=color;
//radius=Math.random()*180/Math.PI;
n=num;
var c3:Number=c2+0x444444;
bou(num,2,c2,0,0);
//bou(num,1,c2,1,0);
//bou(num,1,c3,-1,1);
//bou(num,1,c3,1,-1);
//bou(num,1,c2,0,1);
}
public function move():void{
this.x+=vx;
this.y+=vy;
//this.alpha+=(this.al-this.alpha)/4;
//this.al=0;
this.rotation+=vr;
//this.rotationX+=vr;
}
}