【问题标题】:ActionScript2.0 : Drawing arc for Triangle's angleActionScript2.0:为三角形的角度绘制弧线
【发布时间】:2010-03-30 15:46:09
【问题描述】:

如何使用 flash actionscript 2.0 在随机创建的三角形角度中绘制弧线。

谢谢大家。alt text http://www.freeimagehosting.net/uploads/8289d7feff.png

我想在每个三角形的角度绘制红色弧线。注意:三角形将随机创建。

【问题讨论】:

  • 这个问题有点主观,能否请您补充更多信息(代码、您想要的图片等?)

标签: drawing actionscript-2


【解决方案1】:

一种简单的方法是在每个角上画一个圆,然后使用三角形的副本来遮盖圆,这样只有内部圆弧可见。

例如,在您的库中制作一个名为“circle”的movieClip,其中包含一个以剪辑插入点为中心的未填充红色圆圈(确保在其属性中勾选“Export for 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();


(来源:webfactional.com

【讨论】:

  • 当我在我的 Adob​​e Flash CS 4 Professional 版本中复制和测试您的代码时,我看不到红色弧线。会是什么?
  • 您需要使用 Flash 中的圆形工具手动绘制“圆形”符号。为此,在您的库中创建一个新符号,将其命名为“圆圈”,在其属性中启用“导出为 Actionscript”,然后将符号的外观编辑为一个红色圆圈(无填充),直径可能为 35 像素,以符号的插入点为中心。
  • 如果您需要,这里有一个带有代码驱动圆圈的解决方案:stackoverflow.com/questions/2572271
猜你喜欢
  • 1970-01-01
  • 2014-12-10
  • 1970-01-01
  • 1970-01-01
  • 2016-12-29
  • 2014-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多