我如何显示动作脚本2.0中的随机三角形的坐标? [英] how do i display the coordinates of a random triangle in actionscript 2.0?

查看:200
本文介绍了我如何显示动作脚本2.0中的随机三角形的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用坐标生成一个随机的三角形,它显示了动作脚本2.0中每个角落的弧线与闪光灯8.0。

>这看起来很像你的上一个问题(也很像这个其他问题),但这里有:

  import flash.geom.Point; 

函数randomPoint():Point {//返回舞台上的一个随机点
var p:Point = new Point(Math.floor(Math.random()*(Stage.width -300)),Math.floor(Math.random()* Stage.height));
return p;


函数drawTriangle(mc:MovieClip,q1:Point,q2:Point,q3:Point):Void {//通过3个点绘制一个三角形
var stroke = 2; //三角形的行权重
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);


函数drawCircle(target_mc:MovieClip,x:Number,y:Number):void {
//绘制一个以(x,y) b $ b 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);



函数arcTriangle():MovieClip {//用角弧绘制三角形的主函数
//创建一个新的movieclip t我们的三角形部分
var depth = this.getNextHighestDepth();
var t:MovieClip = this.createEmptyMovieClip(t+ depth,depth);

//定义3个随机点(作为t的属性存储)
t.p1 = randomPoint();
t.p2 = randomPoint();
t.p3 = randomPoint();

//画一个三角形
t.createEmptyMovieClip(triangle,0);
drawTriangle(t.triangle,t.p1,t.p2,t.p3);

//画一个实心的三角形作为掩码
t.createEmptyMovieClip(mask,1);
t.mask.beginFill(0xF0F0F0);
drawTriangle(t.mask,t.p1,t.p2,t.p3);
t.mask.endFill();
t.mask._alpha = 0;

//在每个角落添加一个红圈
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);

//掩盖圆圈,只有内部弧线可见
t.arcHolder.setMask(t.mask);

//显示每个点的坐标(从舞台的左下角开始)
t.createTextField(text1,3,t.p1.x,t.p1。 Y,300100);
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



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


I wanna generate a random triangle with coordinates, which shows the arcs of each corner in actionscript 2.0 with flash 8.0.

解决方案

This looks a lot like your previous question (also a lot like this other question), but here goes:

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

It should look a bit like this when you're done:

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

If either (or both) of my answers are helpful to you, please accept them by clicking the big tick-mark (tick http://roi.webfactional.com/img/so/so_tick.png) on the left-hand side. Thank you.

这篇关于我如何显示动作脚本2.0中的随机三角形的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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