2010-04-02 44 views
1

我想要生成一个随机的三角形坐标,它显示了flash 8.0中actionscript 2.0中每个角落的弧线。如何显示actionscript 2.0中随机三角形的坐标?

+0

可能的重复[我如何显示一个随机三角形的坐标在范围从+10到-10的XY轴在actionscript 2.0中?](http://stackoverflow.com/questions/2572271/how- do-i-display-the-coordinates-of-a-random-triangle-in-a-graph-which-ranges-fr) – user1118321 2015-03-05 14:13:01

回答

2

这看起来很像你previous question(也很像this other question),但这里有云:

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-300)), Math.floor(Math.random()*Stage.height)); 
    return p; 
} 

function drawTriangle(mc:MovieClip, q1:Point, q2:Point, q3:Point):Void {//draws 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 drawCircle(target_mc:MovieClip, x:Number, y:Number):Void { 
    //draws a red circle, centred on (x,y) 
    var radius:Number=18; 
    var k1:Number=Math.tan(Math.PI/8) * radius; 
    var k2:Number=Math.sin(Math.PI/4) * radius; 
    with (target_mc) { 
     lineStyle(2, 0xFF0000, 100, true, "none", "round", "round"); 
     moveTo(x + radius, y); 
     curveTo(radius + x, k1 + y, k2 + x, k2 + y); 
     curveTo(k1 + x, radius + y, x, radius + y); 
     curveTo(-k1 + x, radius+ y, -k2 + x, k2 + y); 
     curveTo(-radius + x, k1 + y, -radius + x, y); 
     curveTo(-radius + x, -k1 + y, -k2 + x, -k2 + y); 
     curveTo(-k1 + x, -radius + y, x, -radius + y); 
     curveTo(k1 + x, -radius + y, k2 + x, -k2 + y); 
     curveTo(radius + x, -k1 + y, radius + x, 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); 
    drawCircle(t.arcHolder,t.p1.x,t.p1.y); 
    drawCircle(t.arcHolder,t.p2.x,t.p2.y); 
    drawCircle(t.arcHolder,t.p3.x,t.p3.y); 

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

    //show the coordinates (from bottom-left corner of the stage) for each point 
    t.createTextField("text1",3,t.p1.x,t.p1.y,300,100); 
    t.text1.text="("+t.p1.x+", "+(Stage.height-t.p1.y)+")"; 
    t.createTextField("text2",4,t.p2.x,t.p2.y,300,100); 
    t.text2.text="("+t.p2.x+", "+(Stage.height-t.p2.y)+")"; 
    t.createTextField("text3",5,t.p3.x,t.p3.y,300,100); 
    t.text3.text="("+t.p3.x+", "+(Stage.height-t.p3.y)+")"; 

    return t; 
} 

var myTriangle:MovieClip = arcTriangle(); 

它看起来有点像这样当您完成:

alt text http://roi.webfactional.com/img/so/triangle2.jpg

如果我的答案中有一方(或两方)对你有帮助,请点击左边的大记号(tick http://roi.webfactional.com/img/so/so_tick.png),接受。谢谢。

+0

感谢您的帮助。有用。 – sailaja 2010-04-03 18:41:16

+0

没问题。不要忘记点击刻度标记... – 2010-04-03 18:59:33

+0

@sailaja接受男人的回答,该死的。 – Discipol 2013-06-13 13:24:15