Add reaction-diffusion in BQN, with video generation script
This commit is contained in:
parent
2dd11ef413
commit
c607954d34
5 changed files with 45 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
*\~
|
*\~
|
||||||
|
out/
|
||||||
|
|
11
generate_animation.sh
Executable file
11
generate_animation.sh
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
mkdir -p out
|
||||||
|
bqn grayscott.bqn
|
||||||
|
# first image is often bad
|
||||||
|
rm out/step00000.pnm
|
||||||
|
# convert all to PNG
|
||||||
|
parallel --jobs 8 "pnmtopng {} > {.}.png" ::: out/*.pnm
|
||||||
|
# generate video
|
||||||
|
ffmpeg -y -framerate 30 -pattern_type glob -i 'out/*.png' -r 30 -vf scale=500:-1 -loop 0 out.mp4
|
31
grayscott.bqn
Normal file
31
grayscott.bqn
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
⟨PBM,PPM⟩←•Import"../bqn-graphics/pnm.bqn"
|
||||||
|
⟨Inferno,Magma,Viridis⟩←•Import"../bqn-graphics/colormaps.bqn"
|
||||||
|
|
||||||
|
# Parameters
|
||||||
|
dt‿da‿db‿f‿k←⟨1.0,0.16,0.08,0.060,0.062⟩
|
||||||
|
n←500 # image size
|
||||||
|
m←10 # seed size at the center of the image
|
||||||
|
|
||||||
|
# Discrete Laplacian
|
||||||
|
Lapl←(+´∘∾1‿¯1(⌽⋈⌽˘)¨<)-4⊸×
|
||||||
|
# Gray-Scott update
|
||||||
|
UpdateA←{𝕨+dt×(da×Lapl 𝕨)+(-𝕨×𝕩⋆2)+f×1-𝕨}
|
||||||
|
UpdateB←{𝕩+dt×(db×Lapl 𝕩)+(𝕨×𝕩⋆2)-𝕩×k+f}
|
||||||
|
Update←(UpdateA⋈UpdateB)´
|
||||||
|
|
||||||
|
# Initialization
|
||||||
|
a←n‿n⥊1
|
||||||
|
Mask←{𝕩‿𝕩↑(-𝕨‿𝕨+𝕩÷2)↑(2×𝕨‿𝕨)⥊1}
|
||||||
|
b←(m Mask n)⌈0.1×n‿n•rand.Range 0
|
||||||
|
|
||||||
|
# Run
|
||||||
|
Step←{stepsize 𝕊 i‿a‿b:
|
||||||
|
•term.OutRaw"."
|
||||||
|
•term.Flush @
|
||||||
|
ap‿bp←Update⍟stepsize a‿b
|
||||||
|
("out/step"∾(¯5↑∾•Fmt¨5-⊸↑i)∾".pnm")•file.Chars (PPM ⌊255×>Inferno¨1-a)∾@+10
|
||||||
|
(i+1)‿ap‿bp
|
||||||
|
}
|
||||||
|
|
||||||
|
50 Step•_while_(600⊸>∘⊑⊢) 0‿a‿b
|
||||||
|
•Out""
|
2
inferno.pnm
Normal file
2
inferno.pnm
Normal file
File diff suppressed because one or more lines are too long
BIN
out.mp4
Normal file
BIN
out.mp4
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue