AS2 绘制山丘曲线 - 随机工作

发布于 2024-11-17 14:14:19 字数 1042 浏览 2 评论 0原文

我有一个数组,其中包含用于绘制多个山丘的点。当我只画直线时,效果很好,但这是不自然的,所以我想让山的顶部/底部部分弯曲。

for(i = 0; i < rPoints.length - 1; i++){
    gamebg.lineStyle(1,0x000000,100);
    gamebg.moveTo(rPoints[i][0] + 45, rPoints[i][1]); //Doesn't directly move to a point so there is empty space for the curved parts.
    if(rPoints[i+1][1] > rPoints[i][1]){ //Determines if it is the top part of a hill or a bottom part, compares y
        gamebg.lineTo(rPoints[i+1][0], rPoints[i+1][1]);
        gamebg.moveTo(rPoints[i+1][0], rPoints[i+1][1]);
        //I didn't add a curveTo here because I only wanted to test it on one so I can make changes easier
    } else {
        gamebg.lineTo(rPoints[i+1][0], rPoints[i+1][1]);
        gamebg.moveTo(rPoints[i+1][0], rPoints[i+1][1]);
        gamebg.curveTo(rPoints[i+1][0]+22, rPoints[i+1][1]-25, rPoints[i+1][1]+45, rPoints[i+1][1]);
    }
}

当我运行代码时,它有时似乎可以工作。

当它起作用时,它仅适用于第一个。 https://i.sstatic.net/5AeG4.png

谢谢!

I have an array that contains the points for drawing multiple hills. When I just draw straight lines it works fine, but that is unnatural so I want to make the top/bottom parts of a hill curved.

for(i = 0; i < rPoints.length - 1; i++){
    gamebg.lineStyle(1,0x000000,100);
    gamebg.moveTo(rPoints[i][0] + 45, rPoints[i][1]); //Doesn't directly move to a point so there is empty space for the curved parts.
    if(rPoints[i+1][1] > rPoints[i][1]){ //Determines if it is the top part of a hill or a bottom part, compares y
        gamebg.lineTo(rPoints[i+1][0], rPoints[i+1][1]);
        gamebg.moveTo(rPoints[i+1][0], rPoints[i+1][1]);
        //I didn't add a curveTo here because I only wanted to test it on one so I can make changes easier
    } else {
        gamebg.lineTo(rPoints[i+1][0], rPoints[i+1][1]);
        gamebg.moveTo(rPoints[i+1][0], rPoints[i+1][1]);
        gamebg.curveTo(rPoints[i+1][0]+22, rPoints[i+1][1]-25, rPoints[i+1][1]+45, rPoints[i+1][1]);
    }
}

When I run the code, it seems to work some times.

When it works, it only works for the first one.
https://i.sstatic.net/5AeG4.png

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丶情人眼里出诗心の 2024-11-24 14:14:20

通过包含点的数组的顺序来确定山的部分要容易得多。在这种情况下,您必须迭代 3 次而不是 1 次。我测试了以下代码,它工作得很好。
*尼古拉斯

/* 
 * ActionScript 2
 * 
 * Drawing some Hills :-) 
 * 
 * The following Loop draws Hills using an Array containing
 * a multiple of 3 Points 
 *  
 *            p5
 *    p2      /\
 *    /\     /  \
 *   /  \   /    \
 *  p1  p3 p4    p6
 * 
 */

var rPoints = [
                // First Hill
                [50,200],
                [100,10],
                [150,200],
                // Second Hill
                [100,200],
                [150,80],
                [200,200],
                // Will not be drawn
                [500,200]
        ];


for(i = 0; i <= rPoints.length-3; i+=3){    

    gamebg.lineStyle(1,0x000000,100);

    // Move to the 1st Point
    gamebg.moveTo(rPoints[i][0], rPoints[i][1]);                
    // Curve to 2nd Point (For a smooth curve the Control Point should be in the Top Left Corner)
    gamebg.curveTo(rPoints[i][0], rPoints[i+1][1], rPoints[i+1][0], rPoints[i+1][1]);
    // Curve to 3rd Point (For a smooth curve the Control Point should be in the Top Right Corner)
    gamebg.curveTo(rPoints[i+2][0], rPoints[i+1][1], rPoints[i+2][0], rPoints[i+2][1]);
    // Close the shape (If you want to)
    gamebg.lineTo(rPoints[i][0], rPoints[i][1]);    
}

it is much easier to determine the parts of the hill by the order of the Array containing the points. In this case you have to iterate by 3 instead of 1. I tested the following code, it worked fine.
*Nicholas

/* 
 * ActionScript 2
 * 
 * Drawing some Hills :-) 
 * 
 * The following Loop draws Hills using an Array containing
 * a multiple of 3 Points 
 *  
 *            p5
 *    p2      /\
 *    /\     /  \
 *   /  \   /    \
 *  p1  p3 p4    p6
 * 
 */

var rPoints = [
                // First Hill
                [50,200],
                [100,10],
                [150,200],
                // Second Hill
                [100,200],
                [150,80],
                [200,200],
                // Will not be drawn
                [500,200]
        ];


for(i = 0; i <= rPoints.length-3; i+=3){    

    gamebg.lineStyle(1,0x000000,100);

    // Move to the 1st Point
    gamebg.moveTo(rPoints[i][0], rPoints[i][1]);                
    // Curve to 2nd Point (For a smooth curve the Control Point should be in the Top Left Corner)
    gamebg.curveTo(rPoints[i][0], rPoints[i+1][1], rPoints[i+1][0], rPoints[i+1][1]);
    // Curve to 3rd Point (For a smooth curve the Control Point should be in the Top Right Corner)
    gamebg.curveTo(rPoints[i+2][0], rPoints[i+1][1], rPoints[i+2][0], rPoints[i+2][1]);
    // Close the shape (If you want to)
    gamebg.lineTo(rPoints[i][0], rPoints[i][1]);    
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文