ActionScript2.0:绘制三角形角度的圆弧 [英] ActionScript2.0 : Drawing arc for Triangle's angle

查看:140
本文介绍了ActionScript2.0:绘制三角形角度的圆弧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Flash ActionScript 2.0在随机创建的三角形角度中绘制圆弧。



谢谢。

(来源: webfactional.com


how can I draw arc in randomize created triangle's angle with flash actionscript 2.0.

Thanks all.alt text http://www.freeimagehosting.net/uploads/8289d7feff.png

I would like to draw red arc at every triangle's angle. Note: The triangle will be created randomly.

解决方案

One simple way would be to draw a circle in each corner, then use a copy of your triangle to mask the circles so only the interior arcs are visible.

For example, make a movieClip in your library named "circle" containing an unfilled red circle centred on the clip's insertion point (make sure you tick "Export for Actionscript" in it's properties).

Then you can draw your triangle something like this:

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();


(source: webfactional.com)

这篇关于ActionScript2.0:绘制三角形角度的圆弧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆