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

iwrjgnb

  1. const canvas = document.createElement('canvas')
  2. const c = canvas.getContext('2d')
  3.  
  4. canvas.width = innerWidth * 2
  5. canvas.height = innerHeight * 2
  6. canvas.style.scale = '.5 .5'
  7. canvas.style.transformOrigin = '0 0' 
  8.  
  9. c.fillStyle = 'rgba(255, 236, 168, 1)'
  10. c.fillRect(0, 0, canvas.width, canvas.height)
  11. document.body.append(canvas)
  12.  
  13. let width = 300
  14. let height = 300
  15.  
  16. function cell(ox = 0, oy = 0) {
  17.  
  18.   let ax = ox + width / 2
  19.   let ay = oy + height / 2
  20.   let x, y
  21.   let r = width * Math.random()
  22.   let rx = r
  23.   let ry = r
  24.   if (Math.random() < .5) rx *= Math.random()
  25.   if (Math.random() < .5) ry *= Math.random()
  26.   let t = Math.random() * 7
  27.  
  28.   let ti = Math.random() * .1 - .05
  29.   let te;
  30.   let dr = 0
  31.   if (ti > 0) {
  32.     te = t + Math.random() * 7
  33.     dr = 1
  34.   } else {
  35.     te = t - Math.random() * 7
  36.   }
  37.   let rm = 0
  38.   if (Math.random() < .5) rm = Math.random() * 3
  39.  
  40.   return () => {
  41.     x = ax + rx * Math.cos(t)
  42.     y = ay + ry * Math.sin(t)
  43.     if (rm !== 0) {
  44.       rx -= rm;
  45.       ry -= rm
  46.     }
  47.     t += ti
  48.     if ((t > te && dr === 1) || (t < te && dr === 0)) {
  49.       return
  50.     }
  51.     c.fillStyle = 'black'
  52.     c.fillRect(x, y, 2, 2)
  53.  
  54.     if (Math.random() < .5) {
  55.       cls.push(cl(x, y))
  56.     }
  57.   }
  58. }
  59.  
  60. function cl(x, y) {
  61.   let vy = .2 + Math.random() * 2 - 1
  62.   let col = 'rgba(0, 0, 0, 0.08)'
  63.   if (Math.random() < .1) col = 'rgba(0, 178, 227, .3)'
  64.   if (Math.random() < .01) col = 'rgba(255, 0, 0, .3)'
  65.   let vx = 0
  66.   if (Math.random() < .03) {
  67.     vx = 1
  68.     vy = 0;
  69.     col = 'rgba(255, 255, 255, .2)'
  70.   }
  71.   let dead = false;
  72.   return () => {
  73.     if (dead) return
  74.     y += vy
  75.     x += vx
  76.     if (Math.random() < .01) {
  77.       dead = true
  78.     }
  79.     c.fillStyle = col
  80.     c.fillRect(x, y, 2, 2)
  81.   }
  82. }
  83.  
  84. let NUM = 5
  85. let cs = []
  86. let cls = []
  87. for (let j = 0; j < NUM; j++) {
  88.   let yy = Math.random() * innerHeight
  89.   let xx = Math.random() * innerWidth
  90.   let num = 5 + ~~(Math.random() * Math.random() * 10)
  91.   if (Math.random() < .3) num = Math.random() * 50
  92.   for (let i = 0; i < NUM; i++) {
  93.     for (let k = 0; k < num; k++) {
  94.       cs.push(cell(xx, yy))
  95.     }
  96.   }
  97. }
  98.  
  99. function loop() {
  100.   cs.forEach(f => f())
  101.   cls.forEach(f => f())
  102.   requestAnimationFrame(loop)
  103. }
  104. loop()

Just posting more code from recent shorts… more here

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