flash on 2014-5-10
/**
* Copyright maxs.maxs.90 ( http://wonderfl.net/user/maxs.maxs.90 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/oMSC
*/
package {
import flash.text.*;
import flash.filters.BlurFilter;
import flash.utils.Proxy;
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class FlashTest extends Sprite {
var coord:Vector.<Number> = new Vector.<Number>();
var tri :Vector.<int> = new Vector.<int>();
var uv :Vector.<Number> = new Vector.<Number>();
var ar_z :Vector.<Number> = new Vector.<Number>();
//
var circle:Shape = new Shape();
var p:Shape = new Shape();
//
var culling:String = "none";
var line_ :Boolean = false;
var polyNum:Number = 15;
var radius :Number = 150;
var height_:Number = 100;
var length_:Number = 2 * radius * Math.PI;
var rotX :int;
var rotY :int;
var speed :Number = 5;
var Yw :Number = stage.stageWidth;
var Yh :Number = stage.stageHeight;
//
var tex:BitmapData = new BitmapData(length_,height_);
var f:BlurFilter = new BlurFilter();
public function FlashTest() {
// write as3 code here..
addChild(p);
addChild(circle);
//
for(var i:int = 0; i < polyNum + 1; i ++){
var x_:int = (Math.cos( (360 / polyNum * i) * (Math.PI / 180) ) * radius) + (Yw /2);
var y_:int = -(height_ / 2);
var z_:int = Math.sin( (360 / polyNum * i) * (Math.PI / 180) ) * radius;
//
ar_z.push(z_,z_);
//
coord.push(x_,y_ + (Yh /2), x_,(y_ * -1) + (Yh /2));
//
tri.push(
(i * 2) + 0,
(i * 2) + 1,
(i * 2) + 3,
//
(i * 2) + 3,
(i * 2) + 2,
(i * 2) + 0);
//
uv.push(
(1 / polyNum) * i,
0,
(1 / polyNum) * i,
1);
//
}
//
var b1:Sprite = btn(0,0,"Line");
addChild(b1);
var b2:Sprite = btn(80,0,"NEGATIVE");
addChild(b2);
var b3:Sprite = btn(160,0,"POSITIVE");
addChild(b3);
var b4:Sprite = btn(240,0,"NONE");
addChild(b4);
//
b1.addEventListener(MouseEvent.CLICK,b1_cl);
b2.addEventListener(MouseEvent.CLICK,b2_cl);
b3.addEventListener(MouseEvent.CLICK,b3_cl);
b4.addEventListener(MouseEvent.CLICK,b4_cl);
//
function b1_cl(event:MouseEvent){ line_ = (line_) ? false : true };
function b2_cl(event:MouseEvent){ culling = "negative" };
function b3_cl(event:MouseEvent){ culling = "positive" };
function b4_cl(event:MouseEvent){ culling = "none" };
//
BMD();
addEventListener(Event.ENTER_FRAME,fr);
}
function fr(event:Event){
rotX = (mouseY < (Yh / 2)) ? -speed : (mouseY > (Yh / 2)) ? speed : 0;
rotY = (mouseX < (Yw / 2)) ? speed : (mouseX > (Yw / 2)) ? -speed : 0;
//
draw();
}
function draw(){
//
for(var i:int = 0; i < (polyNum + 1) * 2; i ++){
p.x = coord[(i * 2) + 0];
p.y = coord[(i * 2) + 1];
p.z = ar_z[i];
//
p.transform.matrix3D.appendTranslation(-(Yw / 2),-(Yh / 2),0);
p.transform.matrix3D.appendRotation(rotX,Vector3D.X_AXIS);
p.transform.matrix3D.appendRotation(rotY,Vector3D.Y_AXIS);
p.transform.matrix3D.appendTranslation((Yw / 2),(Yh / 2),0);
//
coord[(i * 2) + 0] = p.x;
coord[(i * 2) + 1] = p.y;
ar_z[i] = p.z;
}
//
circle.graphics.clear();
if(line_) circle.graphics.lineStyle(3,0x0066ff);
circle.graphics.beginFill(0xff9900);
circle.graphics.beginBitmapFill(tex);
circle.graphics.drawTriangles(coord,tri,uv,culling);
circle.graphics.endFill();
}
function BMD(){
var m:Matrix = new Matrix();
m.createGradientBox(length_,height_);
var color:Array = new Array(0xff0000,0xffff00,0x00ff00,0x00ffff,0x0000ff,0xff00ff,0xff0000);
var alpha:Array = new Array(1,1,1,1,1,1,1);
var rt:Array = new Array(0,42,84,126,168,210,255);
var gr:Shape = new Shape();
gr.graphics.beginGradientFill(GradientType.LINEAR,color,alpha,rt,m);
gr.graphics.drawRect(0,0,length_,height_);
gr.graphics.endFill();
//addChild(gr);
tex.draw(gr);
}
function btn(x_:Number,y_:Number,txt:String){
var cont:Sprite = new Sprite();
cont.buttonMode = true;
//
var t:TextField = new TextField();
var format:TextFormat = new TextFormat("Arial",12,0x000000,true);
format.align = TextFormatAlign.CENTER;
t.defaultTextFormat = format;
t.border = true;
t.borderColor = 0x0066ff;
t.background = true;
t.backgroundColor = 0xff9900;
t.text = txt;
t.width = 80;
t.height = 20;
t.x = x_;
t.y = y_;
//
cont.addChild(t);
//
cont.addEventListener(MouseEvent.MOUSE_OUT,m_out);
cont.addEventListener(MouseEvent.MOUSE_OVER,m_over);
function m_out(event:MouseEvent){
cont.filters = [];
}
function m_over(event:MouseEvent){
cont.filters = [f];
}
//
return cont;
}
}
}