這兩天在研究關(guān)于as畫圖的問(wèn)題,經(jīng)過(guò)一番折騰后終于是出來(lái)了,(部分代碼來(lái)源于 programming macromedia flash mx) 查看效果 AS:
MovieClip.prototype.drawRegAng = function(x, y, r, num, rotation) { /*參數(shù)說(shuō)明:x,y:多邊形的中心坐標(biāo);r:多邊形半徑;num:多邊形邊數(shù);最后一個(gè)是旋轉(zhuǎn)角度*/ var tAngle = (rotation-90)*Math.PI/180; var angle = 2*Math.PI/num; var sin = Math.sin; var cos = Math.cos; num++; this.moveTo(x+r*cos(tAngle), y+r*sin(tAngle)); while (num--) { tAngle += angle; this.lineTo(x+r*cos(tAngle), y+r*sin(tAngle)); } }; this.createEmptyMovieClip("loader", 100); loader.lineStyle(0, 0x000000); //初始化變量 var r=50,num=5,rota=0; var x = Stage.width/2, y = Stage.height/2; loader.drawRegAng(x, y, r, num, rota);
numChange=new Object(); numChange.change=function(evt){ num=evt.target.value; } rChange=new Object(); rChange.change=function(evt){ r=evt.target.value; } rotaChange=new Object(); rotaChange.change=function(evt){ rota=evt.target.value; } bian.addEventListener("change",numChange); jiaodu.addEventListener("change",rotaChange); banjing.addEventListener("change",rChange); function clicked(){ loader.clear(); loader.lineStyle(0, 0x000000); loader.drawRegAng(x, y, r, num, rota); } rSubmit.addEventListener("click",clicked);
圓形: 查看效果 AS: MovieClip.prototype.drawOval=function(x,y,rx,ry){ this.moveTo(x+rx,y); this.curveTo(rx+x,0.4142*ry+y,0.7071*rx+x,0.7071*ry+y); this.curveTo(0.4142*rx+x,ry+y,x,ry+y); this.curveTo(-0.4142*rx+x,ry+y,-0.7071*rx+x,0.7071*ry+y); this.curveTo(-rx+x,0.4142*ry+y,-rx+x,y); this.curveTo(-rx+x,-0.4142*ry+y,-0.7071*rx+x,-0.7071*ry+y); this.curveTo(-0.4142*rx+x,-ry+y,x,-ry+y); this.curveTo(0.4142*rx+x,-ry+y,0.7071*rx+x,-0.7071*ry+y); this.curveTo(rx+x,-0.4142*ry+y,rx+x,y); }
出處:藍(lán)色理想
責(zé)任編輯:moby
◎進(jìn)入論壇Flash專欄版塊參加討論
|