読もう!コミックビーム
// write as3 code here..
package {
import flash.display.Sprite;
import flash.events.Event;
public class Beam03 extends Sprite
{
private var beam:BeamBody;
public function Beam03()
{
addEventListener(Event.ENTER_FRAME,update);
beam = new BeamBody;
addChild(beam);
beam.x = 250;
beam.y = 250;
}
private function update(e:Event):void{
var distX:Number = 250-mouseX;
var distY:Number = 250-mouseY;
var rad:Number = Math.atan2(distY,distX)+Math.PI/2;
beam.rotation = rad/Math.PI*180;
var dist:Number = Math.sqrt(distX*distX+distY*distY);
beam.length = dist;
}
}
}
import flash.display.Sprite;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
import flash.display.Graphics;
import flash.filters.BlurFilter;
import flash.filters.GlowFilter;
class BeamHead extends Sprite{
private var pts1:Array = new Array;
private var pts2:Array = new Array;
public function BeamHead(){
addEventListener(Event.ENTER_FRAME,update);
var i:int ;
var len:Number;
var r:Number;
for(i=0;i<30;i++){
len = Math.random()*10+5;
r = Math.PI*2/30;
pts1.push(new Point(Math.cos(r*i)*len,Math.sin(r*i)*len));
}
for(i=0;i<30;i++){
len = Math.random()*20+10;
r = Math.PI*2/30;
pts2.push(new Point(Math.cos(r*i)*len,Math.sin(r*i)*len));
}
filters = [new GlowFilter()];
}
public function update(e:Event):void{
graphics.clear();
var r:Number = Math.PI*2/30;
var i:int;
var len:Number;
graphics.lineStyle(1,0xff0000);
graphics.moveTo(pts1[0].x,pts1[0].y);
for(i=1;i<30;i++){
graphics.lineTo(pts1[i].x,pts1[i].y);
len = Math.random()*10+5;
pts1[i].x = Math.cos(r*i)*len;
pts1[i].y =Math.sin(r*i)*len;
}
graphics.lineTo(pts1[0].x,pts1[0].y);
pts1[0].x = Math.cos(r*i)*len;
pts1[0].y =Math.sin(r*i)*len;
graphics.lineStyle(1,0xffff00);
graphics.moveTo(pts2[0].x,pts2[0].y);
for(i=1;i<30;i++){
graphics.lineTo(pts2[i].x,pts2[i].y);
len = Math.random()*20+10;
pts2[i].x = Math.cos(r*i)*len;
pts2[i].y =Math.sin(r*i)*len;
}
graphics.lineTo(pts2[0].x,pts2[0].y);
pts2[0].x = Math.cos(r*i)*len;
pts2[0].y =Math.sin(r*i)*len;
}
}
class BeamBody extends Sprite{
private var beams:Array = new Array;
public var length:Number = 100;
private var head:BeamHead;
public function BeamBody(){
addEventListener(Event.ENTER_FRAME,update);
beams.push(new Beam(0xff,20));
beams.push(new Beam(0xffff00,5));
head= new BeamHead();
addChild(head);
head.x = 0;
head.y = length;
filters = [new GlowFilter()];
}
public function update(e:Event):void{
graphics.clear();
for(var i:int = 0;i<beams.length;i++){
beams[i].Draw(graphics,length);
}
head.y = length;
}
}
class Beam {
private var length:Number = 100;
private var unit:Number = 5;
private var col:uint;
private var thick:Number;
public function Beam(col:uint,thick:Number){
this.col = col;
this.thick = thick;
}
public function Draw(g:Graphics,length:int):void{
g.lineStyle(1,col);
g.moveTo(Math.random()*thick-thick/2,0);
for(var i:int = 0;i<length/unit;i++){
g.lineTo(Math.random()*thick-thick/2,i*unit);
}
}
}