Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import or require. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Behavior

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!-- three.min.js r87 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/87/three.min.js"></script>
            
          
!
            
              * {
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
}

body {
  background: #000;
}

            
          
!
            
              // forked from siouxcitizen2.0's "Three.js r87でTorusを表示(WebGL使用)" http://jsdo.it/siouxcitizen2.0/yIG6z
//
//Three.js r87でTorusknotを表示してみました
//マウスドラッグによるTorusknotの回転もつけてみました
//
//
//以下の自分のコードを参考にしました
//
//Three.js r70でTorusknotを表示(WebGL使用)
//http://jsdo.it/siouxcitizen/xocz
//

var scene, renderer;
var camera;
var mesh;

var isMouseDown = false;
 
function init() {
    
    //シーンを作成
    scene = new THREE.Scene(); 
    
    //カメラを作成
    camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 ); 
    camera.position.z = 5; 
    
    //レンダラーを作成
    renderer = new THREE.WebGLRenderer(); 
    renderer.setSize( window.innerWidth, window.innerHeight ); 
    document.body.appendChild( renderer.domElement ); 

    //光源を作成
    var light = new THREE.DirectionalLight("#ffffff", 1);
    var ambient = new THREE.AmbientLight("#333333");
    light.position.set(0, 100, 30);
    scene.add(light);
    scene.add(ambient);
    
    //Torusknotを作成
    var geometry = new THREE.TorusKnotGeometry(1.5, 0.5, 16, 16 );
    var material = new THREE.MeshLambertMaterial({ color: 0xffff00 });
    mesh = new THREE.Mesh( geometry, material ); 
    mesh.position.set(0, 0, 0);
    scene.add( mesh );
            
    document.addEventListener("mousedown", onMouseDown);
    document.addEventListener("touchstart", onMouseDown);
    document.addEventListener("mouseup", onMouseUp);
    document.addEventListener("touchend", onMouseUp);
    document.addEventListener("mousemove", onMouseMove);
    document.addEventListener("touchmove", onMouseMove);

    render();   
}

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


// マウスを押したとき
function onMouseDown(event) {
    isMouseDown = true;
}

// マウスを動かした時
function onMouseMove(event) {
    if (isMouseDown) {
        // 3DモデルをX軸とY軸方向に回転させます
        if ( mesh ) {
            mesh.rotation.y = -getMouseX(event)/50;
            mesh.rotation.x = getMouseY(event)/50;

        }
    }
}

// マウスを離したとき
function onMouseUp(event) {
    isMouseDown = false;
}

function getMouseX(event) {
    if (event.type.indexOf("touch") == -1)
        return event.clientX;
    else
        return event.touches[0].clientX;
}

function getMouseY(event) {
    if (event.type.indexOf("touch") == -1)
        return event.clientY;
    else
        return event.touches[0].clientY;
}

window.addEventListener('DOMContentLoaded', init);

            
          
!
999px

Console