NebulaRemix

Nebula Remix

🍏 Green Fog wallpaper, 🦜🎩 Try Mandelbrot Fractals!

A WebGL reconstruction of the recursive domain warping technique found in Android’s “Magic Smoke” live wallpaper.

It simulates fluid dynamics and cloud formations not through Navier-Stokes equations, but via iterated fractional Brownian motion (FBM), where the noise domain is distorted by the noise itself.

more retro-goods like Phase Beam、Bubble、Nexus、Water Ripple、Grass can be found in livewall.zip

normal phys(gravity sensors supported!):

field:

field(hard):

See Also

Zen Algorithm

Sorting Vis (Text mode) 玩法:tap【记录】,tap播放。

Vid: Stalin & PNG bars sort, With sound + 🐧 Gogo Giegie

^ tutour (PPT)

Game-Life

Image

Image

Image

ASCII Art

Cool 📊 PoV display, Holographic Volume, Open Menu&”Apply”, idShape=SDF Voxel

# ipy Ctrl-K image viewer
import os, cv2, numpy as np
grays = [*" .-:=*+%@#"]
def ascii(img, wh=np.int32(os.popen('stty size', 'r').read().split()[::-1])  ):
  g=np.array(grays)
  a=cv2.cvtColor(cv2.resize(img, wh) , cv2.COLOR_BGR2GRAY)
  b=np.int8(np.interp(a, (0,256), (0,len(g)) ))
  return [*
    (''.join(y) for y in g[b] )
  ]

@get_ipython().pt_app.key_bindings.add('c-k')
def f(ev):
  s=os.popen('ls -t ~/Pictures/Screenshots/* | head -n 1').read().strip()
  print(*ascii(cv2.imread(s)), sep="\n")

# Heart anim
import os, cv2, time
from numpy import*

Nm=array; mix=interp
sh=lambda s: os.popen(s).read()[:-1]

def heart(P, k=.8):
  t = mix(mod(iTime, k), [0, k], [0.3, k])  # Heartbeat
  r = (P[1] - power(abs(P[0]), t))**2 + P[0]**2 - 1.0  # Grayscale function
  return where(r < 0.3, mix(-r, [0, 0.3], [1, 4]), r)

grays = Nm([*" .-:", '\x1B[1;31m=\x1B[0m', *"+*%@#"])
GL=lambda w,h: Nm(meshgrid(linspace(0,1, w), linspace(1,0, h)))

def drawBW(g, wh=flip(int32(sh('stty size').split())), bg=grays):
  a=(1-g(GL(*wh)*5-2-sin(iTime)))*256 if callable(g) else cv2.cvtColor(cv2.resize(g, wh) , cv2.COLOR_BGR2GRAY)
  b=int8(mix(a, (0,256), (0,len(bg)-1) ))
  print('\x1B[0;0H', '\n'.join(''.join(y) for y in bg[b] ))

try: #.: ipy -i
  @get_ipython().pt_app.key_bindings.add('c-k')
  def cropBW(F5):
    g=cv2.imread(sh('zenity --file-selection'))
    drawBW(g)
except:
  for iTime in (x/100 for x in range(0, 600)): drawBW(heart); time.sleep(1/60)

FBm

Logic projection of the “Magic Smoke” shader’s main() loop.

import numpy as np
import matplotlib.pyplot as plt

def noise(p):
  # Grid coords & fractional offsets
  i = np.floor(p).astype(int); f = p - i
  f = f*f*(3 - 2*f) # Hermite smoothing
  
  # Hashing logic (Vectorized py random)
  def h(c):
    return (np.sin(c[...,0]*12.9898 + c[...,1]*78.233) * 43758.5453) % 1

  # Bilinear interpolation across the 4 corners
  a, b = h(i), h(i + [1,0])
  c, d = h(i + [0,1]), h(i + [1,1])
  
  return a + (b-a)*f[...,0] + (c-a)*f[...,1] + (a-b-c+d)*f[...,0]*f[...,1]

def fbm(p, octaves=6):
  v, amp = 0, .5
  for _ in range(octaves):
    v += amp * noise(p); p *= 2.; amp *= .5
  return v

def warp(p, t):
  # q = f(p + d1)
  q = np.stack([fbm(p + t), fbm(p + t + 5.2)], axis=-1)
  # r = f(p + 4q + d2)
  r = np.stack([fbm(p + 4*q + 1.7), fbm(p + 4*q + 9.2)], axis=-1)
  # smokeFlavor = f(p + 4r)
  return fbm(p + 4*r)

# Execute
res = 256
x = np.linspace(0, 5, res)
grid = np.stack(np.meshgrid(x, x), axis=-1)
img = warp(grid, 0.5)

plt.imshow(img, cmap='magma', origin='lower')
plt.axis('off')
plt.show()

Have fun!