repositories

NixDaemon

NixOS pentest workstation as one flake — IceBreaker's successor

clonegit clone https://git.daemon-sec.xyz/NixDaemon.git
planet.zshShell150 lines6.2 KiBraw download
#!/usr/bin/env zsh
# ── planet.zsh : ANSI rotating planet + tilted ring + orbiting moon ──────────
# Rosé Pine base-dark palette, Chi-Rho-free pure geometry. Bounded
# and skippable. Usage: planet.zsh [seconds]   (0 or empty = until keypress)
#   Geometry (depth, illumination) is precomputed once; per frame only the
#   surface stripe rotates and the ring/moon are re-projected → fast enough.

emulate -L zsh
zmodload zsh/mathfunc 2>/dev/null || { print "needs zsh/mathfunc"; return 1 2>/dev/null || exit 1; }
zmodload zsh/datetime 2>/dev/null

local timeout="${1:-0}"
local W=46 H=23
local -F cx=$((W/2.0)) cy=$((H/2.0))
local -F Rx=10.0 Ry=8.5            # planet radii (cols, rows)
local -F tilt=1.05                  # ring tilt
local -F Rring=15.0                 # ring radius (cols)

# vertical Rosé Pine base-dark gradient (top→bottom), "r;g;b"
#
# The light vector is upper-left (lx -0.50, ly -0.55, lz 0.67), so the TOP of
# the sphere is lit and the bottom sits in shadow. Every pixel is then scaled
# by sh = 0.32 + 0.68*ic, which in shadow bottoms out near 0.32×.
#
# Pine survives that at the top (49,116,143 lit) but not at the bottom:
# 0.32× pine = (17,41,50) against a (25,23,36) base — the south pole simply
# dissolved into the terminal. The trailing stops are now warm (rose -> gold),
# which stay legible after the same multiplier and read as a terminator.
local -a grad=(
  "49;116;143" "49;116;143" "156;207;216" "156;207;216" "196;167;231"
  "196;167;231" "235;188;186" "235;188;186" "235;111;146" "235;111;146"
  "246;193;119" "246;193;119" "235;188;186" "235;188;186" "196;167;231"
  "196;167;231" "156;207;216" "235;188;186" "246;193;119"
)
local -a ramp=(' ' '.' ':' '-' '+' 'o' 'O' '0' '8' '@')

# light direction (upper-left, toward viewer), normalized-ish
local -F lx=-0.50 ly=-0.55 lz=0.67

# ── precompute static per-cell sphere data ──────────────────────────────────
# arrays indexed by (y*W+x): s_on (1/0), s_illum, s_lon (base longitude), s_grad
local -a s_on s_illum s_lon s_grad
local -i x y i
local -F nx ny nz d2 illum lon
for (( y=0; y<H; y++ )); do
  for (( x=0; x<W; x++ )); do
    i=$((y*W+x))
    nx=$(( (x-cx)/Rx )); ny=$(( (y-cy)/Ry ))
    d2=$(( nx*nx+ny*ny ))
    if (( d2 <= 1.0 )); then
      nz=$(( sqrt(1.0-d2) ))
      illum=$(( nx*lx + ny*ly + nz*lz ))
      (( illum < 0.10 )) && illum=0.10
      (( illum > 1.0 )) && illum=1.0
      lon=$(( atan(nx, nz) ))                 # base longitude
      s_on[i+1]=1; s_illum[i+1]=$illum; s_lon[i+1]=$lon
      # vertical gradient stop for this row
      s_grad[i+1]=$(( y*${#grad}/H + 1 ))
    else
      s_on[i+1]=0
    fi
  done
done

# ── render loop ──────────────────────────────────────────────────────────────
local start=$EPOCHSECONDS
local -F rot=0.0 morb=0.0
printf '\e[?25l'                                   # hide cursor
printf '\e[2J'                                     # clear once
trap 'printf "\e[?25h\e[0m\n"' EXIT INT TERM

local -a buf bcol                                  # per-frame char + color buffers
local key frame=0
while :; do
  # reset buffers
  buf=(); bcol=()
  for (( i=1; i<=W*H; i++ )); do buf[i]=' '; bcol[i]=''; done

  # back half of ring (depth behind planet)
  local -F t rx rz sx sy depth
  for (( t=0; t<6.2832; t+=0.045 )); do
    rx=$(( Rring*cos(t+rot*0.5) )); rz=$(( Rring*sin(t+rot*0.5) ))
    sx=$(( cx + rx )); sy=$(( cy + rz*sin(tilt)*Ry/Rx )); depth=$(( rz*cos(tilt) ))
    (( depth >= 0 )) && continue
    local -i ix=$(( int(rint(sx)) )) iy=$(( int(rint(sy)) ))
    (( ix<0||ix>=W||iy<0||iy>=H )) && continue
    # far side of the ring: highlightHigh, deliberately dim (was 120;230;200,
    # a mint green that belongs to no Rosé Pine variant)
    i=$((iy*W+ix+1)); buf[i]='·'; bcol[i]="82;79;103"
  done

  # planet (overwrites back ring where it occludes)
  for (( i=1; i<=W*H; i++ )); do
    (( s_on[i] )) || continue
    local -F il=$s_illum[i]
    # rotating surface stripe: shifts with rot → visible spin
    local -F band=$(( sin( (s_lon[i]+rot)*5.0 ) ))
    local -F ic=$(( il + (band>0.35 ? 0.16 : (band<-0.35 ? -0.12 : 0.0)) ))
    (( ic<0.10 )) && ic=0.10; (( ic>1.0 )) && ic=1.0
    local -i ri=$(( int(ic*(${#ramp}-1)) + 1 )); (( ri>${#ramp} )) && ri=${#ramp}
    buf[i]=$ramp[ri]
    # color = vertical gradient dimmed by illumination
    local rgb=${grad[s_grad[i]]}
    local -i r=${rgb%%;*} g=${${rgb#*;}%%;*} b=${rgb##*;}
    local -F sh=$(( 0.32 + 0.68*ic ))
    bcol[i]="$(( int(r*sh) ));$(( int(g*sh) ));$(( int(b*sh) ))"
  done

  # front half of ring (over planet)
  for (( t=0; t<6.2832; t+=0.045 )); do
    rx=$(( Rring*cos(t+rot*0.5) )); rz=$(( Rring*sin(t+rot*0.5) ))
    sx=$(( cx + rx )); sy=$(( cy + rz*sin(tilt)*Ry/Rx )); depth=$(( rz*cos(tilt) ))
    (( depth < 0 )) && continue
    local -i ix=$(( int(rint(sx)) )) iy=$(( int(rint(sy)) ))
    (( ix<0||ix>=W||iy<0||iy>=H )) && continue
    # near side of the ring: love (was 255;120;150, off-palette)
    i=$((iy*W+ix+1)); buf[i]='•'; bcol[i]="235;111;146"
  done

  # orbiting moon
  local -F mx=$(( cx + (Rring+3)*cos(morb) )) my=$(( cy + (Rring+3)*sin(morb)*sin(tilt)*Ry/Rx ))
  local -i mix=$(( int(rint(mx)) )) miy=$(( int(rint(my)) ))
  # moon = gold (246;193;119)
  if (( mix>=0&&mix<W&&miy>=0&&miy<H )); then i=$((miy*W+mix+1)); buf[i]='●'; bcol[i]="246;193;119"; fi

  # paint frame
  printf '\e[H'
  local out='' line='' lastcol=''
  for (( y=0; y<H; y++ )); do
    line=''
    for (( x=0; x<W; x++ )); do
      i=$((y*W+x+1))
      if [[ -n $bcol[i] ]]; then
        [[ $bcol[i] != $lastcol ]] && { line+=$'\e[38;2;'"$bcol[i]"'m'; lastcol=$bcol[i]; }
        line+=$buf[i]
      else
        [[ -n $lastcol ]] && { line+=$'\e[0m'; lastcol=''; }
        line+=' '
      fi
    done
    out+="$line"$'\e[0m'$'\n'; lastcol=''
  done
  printf '%s' "$out"

  rot=$(( rot + 0.13 )); morb=$(( morb + 0.10 )); (( frame++ ))
  # exit conditions: keypress, or timeout
  if read -t 0.06 -k key 2>/dev/null; then break; fi
  if (( timeout > 0 )) && (( EPOCHSECONDS - start >= timeout )); then break; fi
done
printf '\e[?25h\e[0m\n'