cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
                 * {margin: 0; padding: 0;}
            html, body {
                overflow: hidden;
            }
            
          
!
            
              (() => {
    window.addEventListener('load', () => {
        // variables
        let width = window.innerWidth;
        let height = window.innerHeight;
        let targetDOM = document.getElementById('webgl');

        window.addEventListener('mousemove', (event) => {
            let w = window.innerWidth;
            let h = window.innerHeight;
            let x = event.clientX * 2.0 - w; //原点をスクリーンの中心にしている
            let y = event.clientY * 2.0 - h; //原点をスクリーンの中心にしている
            let length = Math.sqrt(x * x + y * y); //大きさ
            x /= length; //単位化する
            y /= length; //単位化する
           box.rotation.z= Math.atan2(x,y);
        }, false);

        // three.js class
        let scene;
        let camera;
        let controls;
        let renderer;
        let geometry;
        let material;
        let box;
        let directional;
        let ambient;

        // parameter
        let CAMERA_PARAMETER = {
            fovy: 60,
            aspect: width / height,
            near: 0.1,
            far: 10.0,
            x: 0.0,
            y: 0.0,
            z: 5.0,
            lookAt: new THREE.Vector3(0.0, 0.0, 0.0)
        };
        let RENDERER_PARAMETER = {
            clearColor: 0x333333,
            width: width,
            height: height
        };
        // material parameter
        let MATERIAL_PARAMETER = {
            color: 0x66B6FF,
            specular: 0xffffff
        };

        // initialize scene
        scene = new THREE.Scene();

        // initialize camera
        camera = new THREE.PerspectiveCamera(
            CAMERA_PARAMETER.fovy,
            CAMERA_PARAMETER.aspect,
            CAMERA_PARAMETER.near,
            CAMERA_PARAMETER.far
        );
        camera.position.x = CAMERA_PARAMETER.x;
        camera.position.y = CAMERA_PARAMETER.y;
        camera.position.z = CAMERA_PARAMETER.z;
        camera.lookAt(CAMERA_PARAMETER.lookAt);

        // initialize renderer
        renderer = new THREE.WebGLRenderer();
        renderer.setClearColor(new THREE.Color(RENDERER_PARAMETER.clearColor));
        renderer.setSize(RENDERER_PARAMETER.width, RENDERER_PARAMETER.height);
        targetDOM.appendChild(renderer.domElement);

        // initialize geometry
        geometry = new THREE.CylinderGeometry(0.5, 0.05,2.5, 5.0);
        material = new THREE.MeshPhongMaterial(MATERIAL_PARAMETER);
        box = new THREE.Mesh(geometry, material);
        scene.add(box);

        // initialize light
        directional = new THREE.DirectionalLight(0xffffff);
        directional.position.set(1.0, 1.0, 1.0);
        ambient = new THREE.AmbientLight(0xffffff, 0.2);
        scene.add(directional);
        scene.add(ambient);

        // rendering
        render();

        function render() {
            renderer.render(scene, camera);
            requestAnimationFrame(render); 
        }

       
    }, false);
})();
            
          
!
999px
Loading ..................

Console