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 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

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.

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

              
                <html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    
    
    </head>
  <body>
    <button id="startBtn">start</button>
    <script>
window.SegX = 128;
window.SegY = 128;
    </script>
    <textarea id="mythread" class="hidecode">
const initStep = 128
const sinc = (x) => {
  if(x==0) {
    return 1.0
  }
  return Math.sin(x*Math.PI)/(x*Math.PI)
}
this.onmessage = (e) =>{
  const SegY = e.data.SegY
  const SegX = e.data.SegX+1
  const divNum = e.data.divNum
  const startX = ((SegX*e.data.plot)/divNum)|0
  const endX = ((SegX*(e.data.plot+1))/divNum)|0
  const maxx=4*Math.PI
  const minx = -4*Math.PI
  const maxy = 4*Math.PI
  const miny = -4*Math.PI
  for(let step=initStep; step >=1;step=step/2) {
    let lpcy = 0
    for(let y = 0; y < SegY + 1; y+=step) {
      let lpc = 0
      let myf=false
      for(let x = startX; x < endX; x+=step) {
        if(lpcy%2 !=0 || lpc % 2 != 0 || step==initStep) {
            const vx = x*(maxx-minx)/SegX+minx
            const vy = y*(maxy-miny)/SegY+miny
            const z = sinc(Math.sqrt(vx*vx+vy*vy))*10  //(x+y)<<1/SegY //Math.min(3,zeta3(new Complex(rr,ri)).abs())*2.5
            postMessage({flag:false,x:x,y:y,z:z,step:step,startx:startX,endx:endX})
            if(step>1) {
              for(let dy=step-1; dy>=0; dy--) {
                for(let dx = step-1; dx>=0;dx--) {
                  if(!(dx==0&&dy==0)&&endX>x+dx&&SegY>=y+dy) {
                    postMessage({flag:false,x:x+dx,y:y+dy,z:z,step:step,startx:startX,endx:endX})
                  }
                }
              }
            }
          }
          lpc++
        }
        lpcy++
      }
      postMessage({flag:true})
    
  }
};
    </textarea>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/88/three.min.js"></script>
    <script>${script}</script>
  </body>
</html>


              
            
!

CSS

              
                *, *:before, *:after {
  box-sizing: border-box; 
}
html {
  font-size: 13px;
}
body {
  font-family: Avenir, "Open Sans", "Helvetica Neue", Helvetica, Arial, Verdana, Roboto, "游ゴシック", "Yu Gothic", "游ゴシック体", "YuGothic", "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", "Meiryo UI", "メイリオ", Meiryo, "MS Pゴシック", "MS PGothic", sans-serif;
  color: #444;
  background-color: hsl(0, 0%, 96%);
}
h1 {
  font-size: 1.8rem;
}
.hidecode{
  display:none;
}


              
            
!

JS

              
                window.onload = () => {
  const elm = document.getElementById("startBtn")
  elm.addEventListener("click",()=>{
    mainProc()
  })
  const mainProc=()=>{
			var scene = new THREE.Scene();
			var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 50 );
			camera.position.z = 30;
      camera.position.y = 15;
      
      camera.lookAt(0,0,0,);
      
			var renderer = new THREE.WebGLRenderer( { antialias: true } );
			renderer.setPixelRatio( window.devicePixelRatio );
			renderer.setSize( window.innerWidth, window.innerHeight );
			renderer.setClearColor( 0x000000, 1 );
			document.body.appendChild( renderer.domElement );

			var lights = [];
			lights[ 0 ] = new THREE.PointLight( 0xeeeeee, 1, 0 );
			lights[ 1 ] = new THREE.PointLight( 0xeeeeee, 1, 0 );
			lights[ 2 ] = new THREE.PointLight( 0xeeeeee, 1, 0 );

			lights[ 0 ].position.set( 0, 300, 0 );
			lights[ 1 ].position.set( 100, 200, 100 );
			lights[ 2 ].position.set( - 100, - 200, - 100 );

			scene.add( lights[ 0 ] );
			//scene.add( lights[ 1 ] );
			scene.add( lights[ 2 ] );

      /*const SegX = 200;
      const SegY = 200;
      */
      const geometry = new THREE.PlaneBufferGeometry( 30, 30, SegX,SegY );
      const material = new THREE.MeshPhongMaterial( {color: 0xf0f0e0, side: THREE.DoubleSide} );
      const plane = new THREE.Mesh( geometry, material );
      scene.add( plane );

      const text = document.getElementById('mythread').value;
      //console.log(text)
      const blob = new Blob([text],{"type" : "text/javascript"});
    
      const wUrl = URL.createObjectURL(blob);
      const myWorker = [];
      const pos = geometry.getAttribute("position");
      const vertices = geometry.attributes.position.array;
      let savedStep=-1;
      const cpuNum =3;
      for(let i=0; i<cpuNum; i++) {
        myWorker[i] = new Worker(wUrl);
        myWorker[i].myid = i
        myWorker[i].onmessage = (e) => {
          if(e.data.flag) {
            pos.needsUpdate = true;
            geometry.computeVertexNormals();
            return;
          }
          //console.log(e.data);
          const x = e.data.x;
          const y = e.data.y;
          const z = e.data.z;
          vertices[(y * (SegX + 1) + x) * 3 + 2] = z;
          //if(savedStep!=e.data.step) {
            //console.log(i,e.data.startx,e.data.endx,e.data.step,e.data.x,e.data.y,e.data.z)
            savedStep=e.data.step
          //}
        };
        myWorker[i].postMessage({plot:i,SegY:SegY,SegX:SegX,divNum:cpuNum});
      }
    //法線ベクトルの自動計算
    geometry.computeFaceNormals();
    geometry.computeVertexNormals();
    
			var prevFog = false;
      plane.rotation.x -= Math.PI/2-0.3;
			const render = () => {
				requestAnimationFrame( render );
				plane.rotation.z += 0.002;
				renderer.render( scene, camera );
			};
		
			render();
	window.addEventListener( 'resize',  () => {

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

				renderer.setSize( window.innerWidth, window.innerHeight );

			}, false );
  }
};

	
              
            
!
999px

Console