)
}
}
)
(
}
{
)
)
(
)
(
(
{
}
)
(
)
}
)
)
{
(
(
)
)
}
)
(
}

Repeatedly Refresh Webpage

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta http-equiv="refresh" content="2"> 
  6.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.   <title>Title</title>
  8. </head>
  9. <body>
  10.   <script>
  11.     document.body.innerHTML = Math.random() * 100;
  12.   </script>
  13. </body>
  14. </html>

Refresh a webpage every two seconds with:

  1. <meta http-equiv="refresh" content="2">

// hacks // html

Polar Forking Tweak

  1. const FOUR_PI = 6 * Math.PI;
  2. const { cos, sin } = Math;
  3.  
  4. const canvas = document.body.appendChild(
  5.   document.createElement('canvas')
  6. );
  7. const c = canvas.getContext('2d');
  8.  
  9. function resize() {
  10.   canvas.width = window.innerWidth;
  11.   canvas.height = window.innerHeight;
  12. }
  13.  
  14. let inc = 0;
  15. function draw() { 
  16.   c.fillStyle = 'rgba(0, 0, 0, .3)'
  17.   c.fillRect(0, 0, canvas.width, canvas.height)
  18.   c.fillStyle = 'white';
  19.  
  20.   const halfWidth = window.innerWidth / 2;
  21.   const halfHeight = window.innerHeight / 2;
  22.   let theta = 0,
  23.     a = 20 * Math.min(window.innerWidth, window.innerHeight) * 0.005,
  24.     x,
  25.     y;
  26.  
  27.   c.save();
  28.   c.translate(halfWidth, halfHeight)
  29.  
  30.   let b = 5 * cos(inc);
  31.   inc += .02;
  32.  
  33.   for (let i = 0; theta < FOUR_PI; i++) {
  34.     let rad = a * (b + 10 * sin(theta / 3));
  35.     // randomly speed-coded and tweaked... leaving as is :D
  36.     x = rad * cos(theta + b / 10) * cos(b / 10 +theta * 2) * cos(theta * 2);
  37.     y = rad * sin(theta * 2) * cos(theta + b / 3) * cos(theta * 2);
  38.     c.fillRect(x,y, 2, 2);
  39.     theta += 0.04;
  40.   }
  41.   c.restore();
  42.  
  43.   requestAnimationFrame(draw)
  44. }
  45.  
  46. resize();
  47. addEventListener('resize', resize);
  48.  
  49. draw();

Just randomly futzing with sin/cos…

Hermit Crab Curves

  1. // six white geometric figures (outlines) superimposed on a black wall.
  2. d = document
  3. b = d.body
  4. S = 600
  5. hs = S / 2
  6. with(Math) {
  7. with(
  8.   b.appendChild(Object.assign(
  9.   d.createElement`canvas`, { width: S, height: S })
  10.   ).getContext`2d`) {
  11.  
  12.     fillRect(0, 0, S, S)
  13.     strokeStyle = '#fff'
  14.  
  15.     canvas.style.transformOrigin = '0 0'
  16.     canvas.style.transform = 'scale(.5)'
  17.  
  18.     lineWidth = 8
  19.  
  20.     H = (
  21.       s = S * .5,
  22.       yp = hs, xp = hs,
  23.       a = 1.234,
  24.       d = 0.1678,
  25.       o = 3.9
  26.       ) => {
  27.         beginPath()
  28.         for (t = 0; t < 6.28; t+=.2) {
  29.           r = sqrt(a ** PI % sin(d * (t ** 2 * a) + o)) * s
  30.           x = xp + r * sin(t);
  31.           y = yp + r * cos(t);
  32.           t === 0 ? moveTo(x, y) : lineTo(x, y)
  33.         }
  34.         closePath()
  35.         stroke()
  36.         fill()
  37.     }
  38.  
  39.     tick = 0
  40.     loop = _ => {
  41.       fillStyle = 'rgba(0, 0, 0, 0.5)'
  42.       fillRect(0, 0, S, S)
  43.       save()
  44.       translate(S/2, S/2)
  45.       scale(.5, .5)
  46.       rotate(tick * 20)
  47.       translate(-S/2, -S/2)
  48.       tick += .0001
  49.       globalAlpha = .8;
  50.       H(S, hs, hs, 1 + tick)
  51.       H(S, hs, hs, 1.1 + tick)
  52.       H(S, hs, hs, 1.2 + tick)
  53.       globalAlpha = 1;
  54.       H(S * .3, hs-S/4, hs, 1, tick)
  55.       H(S * .2, hs+S/4, hs, 1.2, tick, 1.8)
  56.       H(S * .2, hs, hs - S/4, cos(tick), -tick, 5)
  57.       restore()
  58.       requestAnimationFrame(loop)
  59.     }
  60.     loop()
  61.   }
  62. }

Another thing for #genuary2022Sol LeWitt Wall Drawing

Speed Coded Mouse Toy

  1. d = document
  2. b = d.body
  3. b.style.margin = 0
  4. with (b.appendChild(
  5.   Object.assign(d.createElement`canvas`, {
  6.     width: innerWidth,
  7.     height: innerHeight,
  8.   })
  9. ).getContext`2d`) {
  10.   mx = 0
  11.   my = 0
  12.  
  13.   onresize = _ => {
  14.     canvas.width = innerWidth
  15.     canvas.height = innerHeight
  16.   }
  17.  
  18.   onpointermove = e => {
  19.     mx = e.clientX, 
  20.     my = e.clientY
  21.   }
  22.  
  23.   r = 0
  24.   loop = () => {
  25.     save()
  26.     globalCompositeOperation = 'hard-light'
  27.     translate(innerWidth / 2, innerHeight / 2)
  28.  
  29.     rotate(r += .02)
  30.     translate(-innerWidth / 2, -innerHeight / 2)
  31.  
  32.     fillStyle = 'rgba(55, 55, 55, .01)'
  33.     fillRect(0, 0, innerWidth, innerHeight)
  34.  
  35.     fillStyle = 'rgba(116, 196, 221, .02)'
  36.     fillRect(0, my, innerWidth, 20);
  37.  
  38.     fillStyle = 'rgba(255, 255, 255, .02)'
  39.     fillRect(mx, 0, 20, innerHeight);
  40.  
  41.     fillStyle = 'rgba(0, 0, 0, .03)'
  42.     fillRect(0, innerHeight - my, innerWidth, 20);
  43.  
  44.     fillStyle = 'rgba(116, 196, 221, .02)'
  45.     fillRect(innerWidth - mx, 0, 20, innerHeight);
  46.     restore()
  47.     requestAnimationFrame(loop)
  48.   }
  49.   loop()
  50. }

Speed coded mouse toy…

WebGL Tangled Supershape Points

  1. (() => {
  2.   const TWO_PI = Math.PI * 2;
  3.   const m = new Float32Array([
  4.     0, 0, 0, 0,
  5.     0, 0, 0, 0,
  6.     0, 0, 0, 0,
  7.     0, 0, 0, 0
  8.   ])
  9.  
  10.  
  11.   const vert = `
  12.     attribute vec3 vec;
  13.     uniform mat4 mat;
  14.     void main(void) {
  15.       gl_Position = mat * vec4(vec, 1.0);
  16.       gl_PointSize = 2.0;
  17.     }
  18.   `
  19.  
  20.   const frag = `
  21.     void main(void) {
  22.       gl_FragColor = vec4(1., 1., 1., .25);
  23.     }
  24.   `
  25.  
  26.   document.body.style.background = '#232323'
  27.   const gl = document.body
  28.     .appendChild(document.createElement('canvas'))
  29.     .getContext('webgl', {
  30.       preserveDrawingBuffer: true,
  31.       powerPreference: 'high-performance'
  32.     })
  33.  
  34.   Object.assign(gl.canvas.style, {
  35.     position: 'absolute',
  36.     left: '50%',
  37.     top: '50%',
  38.     transform: 'translate(-50%, -50%)',
  39.     outline: '1px solid gray'
  40.   })
  41.  
  42.  
  43.   with(gl) {
  44.     const NUM = 120
  45.     const radius = 0.7
  46.     let verts = []
  47.  
  48.     // Superformula (equations from):
  49.     // https://bsapubs.onlinelibrary.wiley.com/doi/10.3732/ajb.90.3.333
  50.     // http://en.wikipedia.org/wiki/Superformula
  51.     function superShape(a, b, m, n1, n2, n3, scale, x = 0, y = 0, z = 0) {
  52.       const { random, pow, abs, cos, sin } = Math
  53.       // with(Math) { // destrucuring vs the dreaded `with`
  54.         let r = 0
  55.         let p = 0
  56.         let xp = 0
  57.         let yp = 0
  58.         let zp = 0
  59.  
  60.         let rotX = random() * TWO_PI
  61.         let rotY = random() * TWO_PI
  62.         let rotZ = random() * TWO_PI
  63.  
  64.         let cosX = cos(rotX)
  65.         let cosY = cos(rotY)
  66.         let sinX = sin(rotX)
  67.         let sinY = sin(rotY)
  68.  
  69.         while (p <= TWO_PI) {
  70.           let ang = (m * p) / 4
  71.  
  72.           r = pow(pow(abs(cos(ang) / a), n2) + pow(abs(sin(ang) / b), n3), -1 / n1)
  73.           xp = r * cos(p)
  74.           yp = r * sin(p)
  75.  
  76.           p += 0.05
  77.  
  78.           zp = zp * cosX - xp * sinX
  79.           xp = zp * sinX + xp * cosX
  80.           yp = yp * cosY - zp * sinY
  81.           zp = yp * sinY + zp * cosY
  82.  
  83.           verts[inc] = xp * scale + x
  84.           verts[inc + 1] = yp * scale + y
  85.           verts[inc + 2] = zp * scale + z
  86.           inc += 3;
  87.         }
  88.       // }
  89.     }
  90.  
  91.     let inc = 0; 
  92.     for (let i = 0; i < NUM; i++) {
  93.       superShape(1, 1, 1 + ~~(Math.random() * 20),
  94.         ~~(Math.random() * 30),
  95.         ~~(Math.random() * 30),
  96.         ~~(Math.random() * 30), Math.random() * .2,
  97.         Math.random() - .5,
  98.         Math.random() - .5,
  99.         Math.random() - .5 )
  100.     }
  101.  
  102.  
  103.     console.log(verts.length)
  104.     const overts = verts.concat()
  105.     const leng = verts.length / 3
  106.  
  107.     bindBuffer(ARRAY_BUFFER, createBuffer())
  108.     bufferData(ARRAY_BUFFER, new Float32Array(verts), STATIC_DRAW)
  109.  
  110.     const vs = createShader(VERTEX_SHADER)
  111.     shaderSource(vs, vert)
  112.     compileShader(vs)
  113.  
  114.     const fs = createShader(FRAGMENT_SHADER)
  115.     const sp = createProgram()
  116.  
  117.     shaderSource(fs, frag)
  118.     compileShader(fs)
  119.     attachShader(sp, vs)
  120.     attachShader(sp, fs)
  121.     linkProgram(sp)
  122.     useProgram(sp)
  123.  
  124.     const vec = getAttribLocation(sp, 'vec')
  125.     vertexAttribPointer(vec, 3, FLOAT, false, 0, 0)
  126.     enableVertexAttribArray(vec)
  127.  
  128.     const matLoc = getUniformLocation(sp, 'mat')
  129.  
  130.     function rot(x, y, z) {
  131.       // https://wikimedia.org/api/rest_v1/media/math/render/svg/a8e16f4967571b7a572d1a19f3f6468512f9843e
  132.  
  133.       const sinA = Math.sin(x)
  134.       const cosA = Math.cos(x)
  135.       const sinB = Math.sin(y)
  136.       const cosB = Math.cos(y)
  137.       const sinY = Math.sin(z)
  138.       const cosY = Math.cos(z)
  139.  
  140.       m[0] = cosA * cosB
  141.       m[1] = cosA * sinB * sinY - sinA * cosY
  142.       m[2] = cosA * sinB * cosY + sinA * sinY
  143.       m[3] = 0
  144.  
  145.       m[4] = sinA * cosB
  146.       m[5] = sinA * sinB * sinY + cosA * cosY
  147.       m[6] = sinA * sinB * cosY - cosA * sinY
  148.       m[7] = 0
  149.  
  150.       m[8] = -sinB
  151.       m[9] = cosB * sinY
  152.       m[10] = cosB * cosY
  153.       m[11] = m[12] = m[13] = 0
  154.       m[15] = 1
  155.  
  156.       uniformMatrix4fv(matLoc, false, m)
  157.     }
  158.  
  159.     onresize = () => {
  160.       const {
  161.         canvas
  162.       } = gl
  163.       const size = Math.min(innerWidth, innerHeight) - 20
  164.       canvas.width = canvas.height = size
  165.       viewport(0, 0, size, size)
  166.     }
  167.  
  168.     onresize()
  169.  
  170.     let rx = 0, ry = 0, rz = 0
  171.  
  172.     function loop() {
  173.       rx += 0.01
  174.       ry += 0.01
  175.       rz += 0.01
  176.       rot(rx, ry, rz)
  177.  
  178.       disable(DEPTH_TEST)
  179.       enable(BLEND)
  180.       blendFunc(SRC_ALPHA, ONE_MINUS_SRC_ALPHA)
  181.       clearColor(0, 0, 0, 1)
  182.       clear(COLOR_BUFFER_BIT)
  183.       drawArrays(POINTS, 0, leng)
  184.       window.requestAnimationFrame(loop)
  185.     }
  186.     loop()
  187.   }
  188. })()

An interesting accident while playing around with Supershapes and WebgGL points…

snippet.zone ~ 2021-24 /// {s/z}