首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用鼠标交互的二维画布烟雾示例。

使用鼠标交互的二维画布烟雾示例。
EN

Stack Overflow用户
提问于 2013-04-06 05:09:42
回答 1查看 2.1K关注 0票数 0

我正在寻找一个使用HTML2D画布的烟雾效果的例子,其中烟雾是由用户在烟雾中移动鼠标以使烟雾受到干扰而产生的。

EN

回答 1

Stack Overflow用户

发布于 2013-11-01 08:23:01

我不知道你是否仍然对此感兴趣,但是,这里看看this,而不是检查粒子是否接触了边缘,你应该提供鼠标x,y坐标:

代码语言:javascript
运行
复制
function init() {
    var canvas = document.getElementById('myCanvas');
    if (canvas.getContext) {

        // Set the context variable so it can be re-used
        context = canvas.getContext('2d');

        // Create the particles and set their initial positions and velocities
        for(var i=0; i < particleCount; ++i){
            var particle = new Particle(context);

            // Set the position to be inside the canvas bounds
            particle.setPosition(generateRandom(0, canvasWidth), generateRandom(0, canvasHeight));

            // Set the initial velocity to be either random and either negative or positive
            particle.setVelocity(generateRandom(-maxVelocity, maxVelocity), generateRandom(-maxVelocity, maxVelocity));
            particles.push(particle);            
        }
    }
    else {
        alert("Please use a modern browser");
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15843611

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档