我想生成具有坐标的随机三角形,其示出了在ActionScript 2.0每个角与闪光8.0的弧。
Answer 1:
这看起来很像你前面的问题 (也有很多像这样的其他问题 ),但在这里有云:
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();
它看起来有点像这样当您完成:
(来源: webfactional.com )
如果我的答案,无论(或两者)对您有帮助,请点击大刻度线接受他们( ) 在左手侧。 谢谢。
文章来源: how do i display the coordinates of a random triangle in actionscript 2.0?