css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm 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. We'll also process your JavaScript with Babel.

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

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.

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.

              <html lang="ja">
  <canvas id="myCanvas"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/89/three.min.js"></script>
              // ページの読み込みを待つ
    window.addEventListener('load', init);

    function init() {
      let rot = 0; // 角度
      let mouseX = 0; // マウス座標

      // サイズを指定
      const width = 960;
      const height = 540;

      // レンダラーを作成、引数にcanvasを指定
      const renderer = new THREE.WebGLRenderer({
        canvas: document.querySelector('#myCanvas')
      renderer.setSize(width, height);

      // シーンを作成、シーンとは3D空間のことで3Dオブジェクトなどを置く場所
      const scene = new THREE.Scene();

      // カメラを作成、カメラはどの角度から見るかを指定
      //usage: new THREE.PerspectiveCamera(画角(どれくらいの距離から見るか), アスペクト比(縦横比));
      const camera = new THREE.PerspectiveCamera(45, width / height);
      camera.position.set(0, 0, +1000);
      //-----箱の生成 st-----//
      // 箱を作成、three.jsでは「メッシュ」と呼ばれるものを使ってオブジェクトを描画する。
      //usage: new THREE.BoxGeometry(幅, 高さ, 奥行き)
      const geometry = new THREE.BoxGeometry(400, 400, 400);
      // 適当なカラーを割り振るmaterialを生成
      //usage: new THREE.MeshNormalMaterial();
      const material = new THREE.MeshNormalMaterial();
      const box = new THREE.Mesh(geometry, material);
      //-----箱の生成 en-----//

      //-----球体の生成 st-----//
      //usage: 1.SphereGeometry(radius(半径) : Float, 2.widthSegments(横が何分割か): Integer, 3.heightSegments(縦が何分割か) : Integer, 4.phiStart(y軸回転開始角度) : Float, 5.phiLength(y軸回転角度) : Float, 6.thetaStart(x軸回転開始角度) : Float, 7.thetaLength (x軸回転角度): Float)
         const sphere = new THREE.SphereGeometry(300, 13, 7 , 0, 6.3, 0, 3.1);
         const smaterial = new THREE.MeshStandardMaterial({color: 'red'});
         const circle = new THREE.Mesh(sphere, smaterial);
      //---- en-----//

      //---- 平行光源 st-----//
      const lightCreater = ()=> {
        const directionalLight = new THREE.DirectionalLight(0xFFFFFF);
        directionalLight.position.set(1, 1, 1);
        // シーンに追加
      //---- en-----//

      // scene.add(box);
      // scene.add(imgMesh);
      document.addEventListener('mousemove', (event) => {
        mouseX = event.pageX;

      // 毎フレーム時に実行されるループイベントです
      function tick() {
        circle.rotation.x += 0.01;

        //usage: renderer.render(scene, camera);
        renderer.render(scene, camera); // レンダリング
        //usage:  requestAnimationFrame(繰り返す関数)

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................