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

Fake RNG

  1. let anchors
  2. let idx
  3. let leng = 10
  4. let size = 200
  5. let px = 0
  6. let py = 0
  7.  
  8. function seed() {
  9.   idx = 0
  10.   anchors = (Date.now() + '').split``
  11.     .reverse()
  12.     .map(v => parseFloat(v) / 10)
  13.     .splice(0, leng)
  14. }
  15.  
  16. let last = 0
  17. let zoom = 1
  18. function rand() {
  19.   if (idx > size * size) seed()
  20.  
  21.   px += zoom
  22.   py += ~~(px / size)
  23.  
  24.   if (px >= size) px = 0
  25.   if (py >= size) py = 0
  26.  
  27.   const point = {
  28.     x: anchors[idx % leng],
  29.     y: anchors[(idx + 1) % leng]
  30.   }
  31.   idx++
  32.  
  33.   let dists = []
  34.   for (let i = 0; i < anchors.length; i += 2) {
  35.     let dx = px - anchors[i] * size
  36.     let dy = py - anchors[i + 1] * size
  37.     dists.push(Math.sqrt(dx * dx + dy * dy))
  38.   }
  39.   dists.sort()
  40.   last += (dists[0] / size - last) / 4
  41.   return last
  42. }
  43.  
  44. seed()
  45.  
  46. let d = document
  47. let b = d.body
  48. with (b.appendChild(
  49.   Object.assign(d.createElement`canvas`, { width: 400, height: 400 })
  50. ).getContext`2d`) {
  51.   fillStyle = 'black'
  52.   fillRect(0, 0, 400, 400)
  53.  
  54.   for (let i = 0; i < 200; i++) {
  55.     for (let j = 0; j < 200; j++) {
  56.       const c = rand() * 255
  57.       fillStyle = `rgb(${c}, ${c}, ${c})`
  58.       fillRect(j * 2, i * 2, 1, 2)
  59.     }
  60.   }
  61. }

Another one for genuary “Create your own pseudo-random number generator and visually check the results.”

Average Some Curves

  1. const canvas = document.body.appendChild(
  2.   document.createElement('canvas')
  3. );
  4. const c = canvas.getContext('2d');
  5.  
  6. function resize() {
  7.   canvas.width = window.innerWidth;
  8.   canvas.height = window.innerHeight;
  9.   draw();
  10. }
  11.  
  12. function draw() {
  13.   c.clearRect(0, 0, canvas.width, canvas.height);
  14.  
  15.   Math.min(window.innerWidth, window.innerHeight) * 0.0015;
  16.   const iter = 300,
  17.         halfWidth = window.innerWidth / 2,
  18.         halfHeight = window.innerHeight / 2;
  19.   let rad = 50, rad2 = 50, theta = 0, x, y;
  20.   let x2, y2;
  21.   for (let i = 0; i < 100; i++) {
  22.     c.fillStyle = 'blue';
  23.     x = halfWidth + rad * Math.cos(theta);
  24.     y = halfHeight + rad * Math.sin(theta);
  25.     c.fillRect(x, y, 5, 5);
  26.  
  27.     c.fillStyle = 'red';
  28.  
  29.     rad2 = 80 + rad * Math.cos(theta * 3);
  30.     x2 = halfWidth + rad2 * Math.cos(theta);
  31.     y2 = halfHeight + rad2 * Math.sin(theta);
  32.     c.fillRect(x2, y2, 5, 5);
  33.  
  34.     c.fillStyle = 'green';
  35.     c.fillRect((x2 + x) / 2, (y2 + y) / 2, 5, 5);
  36.  
  37.     theta += .1;
  38.   }
  39. }
  40.  
  41. resize();
  42. window.addEventListener('resize', resize);

1×1 Transparent Image DataUri Gif

  1. data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==

Have used this one in the past – super useful – guessing I got it from here but not totally sure…

If I ever get around to making the updated version of QuickShader available – it’s used in there…

EDIT:

  1. // ¯\_(:P)_/¯
  2. Object.assign(document.createElement`canvas`,{width:1,height:1}).toDataURL()
  3.  
  4. //// ... 
  5. document.body.innerHTML=`<canvas id=x>`;x.width=x.height=1;x.toDataURL()

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…

Grads

  1. const grad = {
  2.   gen(c) {
  3.     const canvas = c.canvas;
  4.     const t = Math.random() * 2 * Math.PI;
  5.     const cx = canvas.width / 2;
  6.     const cy = canvas.height / 2;
  7.     const r = Math.max(cx, cy);
  8.     const x1 = cx * Math.cos(t);
  9.     const y1 = cy * Math.sin(t);
  10.     const x2 = cx * Math.cos(t + Math.PI);
  11.     const y2 = cy * Math.sin(t + Math.PI);
  12.  
  13.     const drawFn = c => {
  14.       const g = c.createLinearGradient(x1, y1, x2, y2);
  15.       g.addColorStop(0, 'white');
  16.       g.addColorStop(1, 'black');
  17.  
  18.       c.fillStyle = g;
  19.       c.fillRect(0, 0, canvas.width, canvas.height);
  20.     };
  21.  
  22.     drawFn(c);
  23.   }
  24. };
  25.  
  26. Object.assign(document.body.style, { 
  27.     margin: 0,
  28.     display: 'grid',
  29.     'grid-template-columns': '1fr 1fr 1fr',
  30.   });
  31. const modes = 'screen,overlay,darken,lighten,color-dodge,color-burn,hard-light, soft-light,difference,exclusion,hue,saturation,color,luminosity,multiply'.split(',');
  32.  
  33. for (let j = 0; j < 21; j++) { 
  34.   const SIZE = 200;
  35.   const c = document.body.appendChild(
  36.     document.createElement('canvas')
  37.   ).getContext('2d');
  38.  
  39.   c.canvas.width = c.canvas.height = SIZE;
  40.   Object.assign(c.canvas.style, {
  41.     position: 'relative', 
  42.     width: '100%'
  43.   })
  44.  
  45.  
  46.   c.fillStyle = `hsl(${Math.random() * 20 + 190}deg, 50%, 50%)`
  47.   c.fillRect(0, 0, SIZE, SIZE)
  48.  
  49.   for (let i = 0; i < 5; i++) { 
  50.     c.globalAlpha = .5;
  51.     c.globalCompositeOperation = modes[~~(Math.random() * modes.length)]
  52.     grad.gen(c)
  53.   }
  54. }

Not sure what this is… used the random gradient code and variations on it a few times….

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