• 使用two.js生成的卫星环绕动画效果


    来源:GBin1.com

    使用two.js生成的卫星环绕动画效果

    two.js是一个帮助你实现绘图和动画效果的类库,同时支持三种前端绘图实现:

    • webgl
    • svg
    • 2d画布

    使用这个类库,可以方便的支持这三种不同的实现,你只需要设置参数:Two.Types.canvas, Two.Types.svg, or Two.Types.webgl

    下面是使用two.js生成的一个动画效果:

    http://www.gbtags.com/gb/debug/592abb4d-6449-4654-a824-0232c0c3b110.htm

    相关JS代码如下:

        var el = document.getElementById("main"),
        two = new Two({
         '800',
        height: '600'
        });
        two.appendTo(el);
         
        var earthAngle = 0,
        moonAngle = 0,
        distance = 30,
        radius = 50,
        padding = 100,
        orbit = 200,
        offset = orbit + padding,
        orbits = two.makeGroup();
         
        var earthOrbit = two.makeCircle(offset, offset, orbit);
        earthOrbit.noFill();
        earthOrbit.linewidth = 2;
        earthOrbit.stroke = "#EFEFEF";
        orbits.add(earthOrbit);
        two.update();
         
        var pos = getPositions(earthAngle++, orbit),
        earth = two.makeCircle(pos.x + offset, pos.y + offset, radius);
        earth.stroke = "#444";
        earth.linewidth = 3;
        earth.fill = "#CCCCCC";
         
        var moonOrbit = two.makeCircle(earth.translation.x, earth.translation.y, radius + distance);
        moonOrbit.noFill();
        moonOrbit.linewidth = 2;
        moonOrbit.stroke = "#ccc";
        orbits.add(moonOrbit);
        var pos = getPositions(moonAngle, radius + distance),
        moon = two.makeCircle(earth.translation.x + pos.x, earth.translation.y + pos.y, radius / 4);
        moonAngle += 5;
        moon.fill = "#474747";
         
         
         
        two.bind("update", function (frameCount) {
        var pos = getPositions(earthAngle++, orbit);
        earth.translation.x = pos.x + offset;
        earth.translation.y = pos.y + offset;
         
        var moonPos = getPositions(moonAngle, radius + distance);
        moon.translation.x = earth.translation.x + moonPos.x;
        moon.translation.y = earth.translation.y + moonPos.y;
        moonAngle += 5;
        moonOrbit.translation.x = earth.translation.x;
        moonOrbit.translation.y = earth.translation.y;
        });
         
        function getPositions(angle, orbit) {
        return {
        x: Math.cos(angle * Math.PI / 180) * orbit,
        y: Math.sin(angle * Math.PI / 180) * orbit
        };
        }
        two.play();

    网站地址:http://jonobr1.github.io/two.js

    via 极客标签

    来源:使用two.js生成的卫星环绕动画效果

  • 相关阅读:
    利用js在Table中追加数据
    C#API配置跨域
    C#linq查询DataTable
    erlang格式化输出
    erlang 的源代码保护机制
    MP3格式音频文件结构解析
    使用异步 I/O 大大提高应用程序的性能
    虚拟机安装mac 关键是换引导
    C/C++规则整理
    字节对齐
  • 原文地址:https://www.cnblogs.com/gbin1/p/3182075.html
Copyright © 2020-2023  润新知