2010-03-30 88 views

回答

1

一種簡單的方法是在每個角上繪製一個圓,然後使用三角形的副本來掩蓋圓,以便只有內圓弧可見。

例如,在名爲「circle」的庫中製作一個包含以剪輯插入點爲中心的未填充的紅色圓圈的影片剪輯(請確保在其屬性中勾選「導出爲ActionScript」)。

然後你就可以畫出你的三角形是這樣的:

import flash.geom.Point; 

function randomPoint():Point { //return a random point on the stage 
    var p:Point = new Point(Math.floor(Math.random()*Stage.width), Math.floor(Math.random()*Stage.height)); 
    return p; 
} 

function drawTriangle(mc:MovieClip, q1:Point, q2:Point, q3:Point):Void {//draw a triangle through 3 points 
    var stroke=2;//line weight of triangle 
    mc.lineStyle(stroke, 0x000000, 100, true, "none", "round", "round"); 
    mc.moveTo(q1.x, q1.y); 
    mc.lineTo(q2.x, q2.y); 
    mc.lineTo(q3.x, q3.y); 
    mc.lineTo(q1.x, q1.y); 
} 

function arcTriangle():MovieClip { //main function to draw a triangle with corner arcs 
    //make a new movieclip t which will hold our triangle parts 
    var depth=this.getNextHighestDepth(); 
    var t:MovieClip = this.createEmptyMovieClip("t"+depth, depth); 

    //define 3 random points (stored as properties of t) 
    t.p1=randomPoint(); 
    t.p2=randomPoint(); 
    t.p3=randomPoint(); 

    //draw a triangle 
    t.createEmptyMovieClip("triangle", 0); 
    drawTriangle(t.triangle, t.p1, t.p2, t.p3); 

    //draw a filled triangle to use as a mask 
    t.createEmptyMovieClip("mask", 1); 
    t.mask.beginFill(0xF0F0F0); 
    drawTriangle(t.mask, t.p1, t.p2, t.p3); 
    t.mask.endFill(); 
    t.mask._alpha=0; 

    //add a red circle to each corner 
    t.createEmptyMovieClip("arcHolder", 2); 
    t.arcHolder.attachMovie("circle", "arc1",1,{_x:t.p1.x, _y:t.p1.y}); 
    t.arcHolder.attachMovie("circle", "arc2",2,{_x:t.p2.x, _y:t.p2.y}); 
    t.arcHolder.attachMovie("circle", "arc3",3,{_x:t.p3.x, _y:t.p3.y}); 

    //mask the circles so only the interior arcs are visible 
    t.arcHolder.setMask(t.mask); 

    return t; 
} 

var myTriangle:MovieClip = arcTriangle(); 

et voila http://roi.webfactional.com/img/so/triangle.jpg

+0

當我在我的Adobe Flash CS 4 Professional版本中複製並測試您的代碼時,我看不到紅色圓弧。它會是什麼? – RedsDevils 2010-03-30 23:08:15

+0

您需要使用Flash中的圓形工具手動繪製「圓形」符號。爲此,請在庫中創建一個新符號,將其命名爲「circle」,在其屬性中啓用「導出爲Actionscript」,然後將該符號的外觀編輯爲直徑爲35像素的紅圈(無填充)以符號的插入點爲中心。 – 2010-03-31 06:17:38

+0

下面是一個代碼驅動的解決方案,如果你需要它:http://stackoverflow.com/questions/2572271 – 2010-04-09 15:17:15