iT邦幫忙

1

js 學習:動態畫線條

  • 分享至 

  • xImage
  •  

使用的是three.js組件畫線條;
每秒畫一次,一直畫下去;
要先裝好three.js

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>My first three.js app</title>
    <style>
        body {
            margin: 0;
        }
    </style>
</head>

<body>
    <script src="node_modules/three/build/three.js"></script>
    <script>
        const renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);

        const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 500);
        camera.position.set(0, 0, 100);
        camera.lookAt(0, 0, 0);

        const scene = new THREE.Scene();
        var count = 1;
        //create a white LineBasicMaterial
        var paintWhiteLine = function () {
            const material = new THREE.LineBasicMaterial({ color: 0xffffff });
            const points = [];
            points.push(new THREE.Vector3(- (10 +count), 0, 0));
            points.push(new THREE.Vector3(0, (10 * count), 0));
            points.push(new THREE.Vector3(10 +count, 0, 0));
            count++;
            const geometry = new THREE.BufferGeometry().setFromPoints(points);
            const line = new THREE.Line(geometry, material);
            scene.add(line);
            renderer.render(scene, camera);
        }
        paintWhiteLine();
        //draw every second
        var animate = function () {
            setInterval(paintWhiteLine,1000);      
        }
        animate(); // initial call {% endcomment %}
    </script>
</body>

</html>

Yes


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言