Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="ja">
  <head>
    <!-- CDNからThree.js読み込み -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.js"></script>
  </head>
  <body>
    <!-- (表示) 出力を保持する -->
    <div id="WebGL-output"></div>

    <!-- Three.jsコードの記述 -->
    <script type="text/javascript">
      var scene; // シーン定義
      var camera; // カメラ定義
      var renderer; // レンダラー定義

      function init() {
        /* シーン作成 */
        scene = new THREE.Scene();

        /* カメラ作成 */
        camera = new THREE.PerspectiveCamera(
          45, // 視野
          window.innerWidth / window.innerHeight, // アスペクト
          0.1, // どの程度のカメラ距離から描画を始めるか
          1000 // どのくらい遠くまで見えるか
        );
        scene.add(camera);

        // カメラのポジションと向きを決定
        camera.position.x = -30;
        camera.position.y = 40;
        camera.position.z = 30;
        camera.lookAt(scene.position); // シーンの中心にカメラを向ける

        /* レンダラー作成 */
        renderer = new THREE.WebGLRenderer();
        renderer.setClearColor(new THREE.Color(0xeeeeee));
        renderer.setSize(window.innerWidth, window.innerHeight);

        /* ライト作成 */
        // 均等光源(影ができない)
        var ambientLight = new THREE.AmbientLight(0x0c0c0c);
        scene.add(ambientLight);
        // 点座標への光源(影ができる)
        var spotLight = new THREE.SpotLight(0xffffff);
        spotLight.position.set(-20, 30, -5);
        spotLight.castShadow = true; // 影を落とす
        scene.add(spotLight);

        /* 球体作成 */
        var sphereGeometry = new THREE.SphereGeometry(9, 20, 20);
        var sphereMaterial = new THREE.MeshLambertMaterial({ color: 0x1327ff });
        var sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);

        // 球体ポジション等
        sphere.position.x = 0;
        sphere.position.y = 0;
        sphere.position.z = 0;
        sphere.castShadow = true;

        // オブジェクトをシーンに追加
        scene.add(sphere);

        // レンダラーの出力をhtmlに追加する
        document
          .getElementById("WebGL-output")
          .appendChild(renderer.domElement);

        // シーンを描画
        render();
        // シーンを描画する関数
        function render() {
          // 表示
          renderer.render(scene, camera);
          // レンダリング(再帰)
          requestAnimationFrame(render);
        }
      }

      // 表示が終わってからThree.js関連処理(関数init)を実行
      window.addEventListener("load", init());
    </script>
  </body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console