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" />
    
    <title>Zeta function plot</title>
    
    <style>${style}</style>
  </head>
  <body>
    <button id="startBtn">Start</button>
   
    <textarea id="mythread" class="hidecode">
      // original : https://gist.github.com/bellbind/7ce0a9364d3d43f231b5

// Complex type
const Complex = function (real, imag) {
    if (real instanceof Complex) return real
    
    imag = imag || 0
    return Object.freeze(Object.create(Complex.prototype, {
        real: {value: real, enumerable: true},
        imag: {value: imag, enumerable: true},
    }))
}
Complex.fromPolar = (r, theta) => {
    return Complex(r * Math.cos(theta), r * Math.sin(theta))
}
Complex.eq = (a, b) => {
    a = Complex(a), b = Complex(b)
    return a.real === b.real && a.imag === b.imag
}

Complex.prototype.norm = function () {
    return this.real * this.real + this.imag * this.imag
}

Complex.prototype.r = Complex.prototype.abs = function () {
    return Math.sqrt(this.norm())
}
Complex.prototype.theta = Complex.prototype.arg = function () {
    return Math.atan2(this.imag, this.real)
}
Complex.prototype.add = function (b) {
    b = Complex(b)
    return Complex(this.real + b.real, this.imag + b.imag)
}
Complex.prototype.sub = function (b) {
    b = Complex(b)
    return Complex(this.real - b.real, this.imag - b.imag)
}
Complex.prototype.mul = function (b) {
    b = Complex(b)
    const real = this.real * b.real - this.imag * b.imag
    const imag = this.real * b.imag + this.imag * b.real
    return Complex(real, imag)
}
Complex.prototype.neg = function () {
    return Complex(-this.real, -this.imag)
}
Complex.prototype.conj = function () {
    return Complex(this.real, -this.imag)
}
Complex.prototype.inv = function () {
    const base = this.norm()
    return Complex(this.real / base, -this.imag / base)
}
Complex.prototype.div = function (b){
    b = Complex(b)
    const base = b.norm()
    const c = this.mul(b.conj())
    return Complex(c.real / base, c.imag / base)
}
Complex.prototype.pow = function (b) {
    b = Complex(b);
    const r = this.r(), theta = this.theta();
    const abs = Math.pow(r, b.real) * Math.exp(-b.imag * theta);
    const arg = b.imag * Math.log(r) + b.real * theta;
    return Complex.fromPolar(abs, arg);
}
Complex.prototype.exp = function () {
    return Complex.fromPolar(Math.exp(this.real), this.imag);
};
Complex.prototype.log = function (n) {
    n = n || 0;
    return Complex(Math.log(this.r()), this.theta() + 2 * n * Math.PI);
};
Complex.prototype.proj = function () {
    if (this.real === Infinity || this.real === -Infinity ||
        this.imag === Infinity || this.imag === -Infinity) return Complex.inf;
    return this;
}

Complex.c0 = Complex(0)
Complex.c1 = Complex(1)
Complex.c2 = Complex(2)
Complex.i = Complex.c1i = Complex(0, 1)
Complex.inf = Complex(Infinity)

// util
const range = (start, end) => {
    const l = end - start
    const a = new Array(l)
    for (let i = 0; i < l; i++) a[i] = start + i
    return a
}
                          
const csum = function (a) {
    let r = Complex.c0;
    for (let i = 0, l = a.length; i < l; i++) r = r.add(a[i]);
    return r;
};
const binom = (n, k) => {
    k = n - k < k ? n - k : k; // use shorter side for loop
    // use add with array for avoiding overflow by mul n*(n-1)
    //   e.g. 3C2: 1 0 0 => 1 1 0 => 1 2 1  => 1 3 3  <= result
    const a = new Array(k + 1);
    a[0] = 1;
    for (let i = 1; i <= k; i++) a[i] = 0;
    for (let i = 0; i < n; i++) {
        for (let j = k; j >= 1; j--) a[j] += a[j - 1];
    }
    return a[k]
};

const sign = (k) => {
    return (k % 2) ? -1 : 1
}

const zeta3 = (s, t) => {
    t = t || 100
    s = Complex(s)
    if(s.imag.value == 0 && s.real.value <0 && s.real.value % 2 == 0) {
      return 0
    }
    if (Complex.eq(s, Complex.c1)) return Complex.inf;
    // zeta(s) = 1/(1 - 2^(1-s)) * 
    //           S(n=1..inf| 1/2^(n+1) * S(k=0..n| -1^k * C(n,k) / (k+1)^s))
    // (s != 1)
    const sn = s.neg(), two = Complex.c2;
    return csum(range(0, t).map((n) => {
        return csum(range(0, n + 1).map((k) => {
            return Complex(k + 1).pow(sn).mul(sign(k) * binom(n, k));
        })).div(two.pow(n + 1));
    })).div(two.pow(sn.add(1)).neg().add(1));
};
const initStep = 128;

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
  
  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
      const ri = (y/SegY)*(25+25)-25
      for(let x = startX; x < endX; x+=step) {
        if(lpcy%2 !=0 || lpc % 2 != 0 || step==initStep) { // 
            const rr = (x/SegX)*(14+11)-11
            const z = Math.min(3,zeta3(new Complex(rr,ri)).abs())*5
            postMessage({flag:myf,x:x,y:y,z:z,step:step,startx:startX,endx:endX})
              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++
        }
        postMessage({flag:true,step:step,y:y,endx:endX})
        lpcy++
      }
  }
}
    </textarea>
       <script>
window.SegX = 128
window.SegY = 128
    </script>
    <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 = () => {
			const scene = new THREE.Scene()
			const 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,)
      
			const 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 )

			const 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 = navigator.hardwareConcurrency||1
      console.log(`cpuNum = ${cpuNum}`)
      for(let i=0; i<cpuNum; i++) {
        myWorker[i] = new Worker(wUrl);
        myWorker[i].onmessage = (e) => {
          if(e.data.flag) {
            pos.needsUpdate = true
            geometry.computeVertexNormals()
            //console.log(e.data.step,e.data.y,e.data.endx)
            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
          
        }
                  myWorker[i].postMessage({plot:i,SegY:SegY,SegX:SegX,divNum:cpuNum});
      }
    //法線ベクトルの自動計算
    geometry.computeFaceNormals()
    geometry.computeVertexNormals()
    
			const 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