reaction-diffusion/grayscott.dyalog

22 lines
715 B
APL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

⎕IO0
⍝ Discrete Laplacian
lapl((+/1 ¯1(+)¨)-(4×))
⍝ Gray-Scott update
diffa{dt×(da×lapl )+(-×*2)+f×1-}
diffb{dt×(db×lapl )+(×*2)-×k+f}
update{+([0])((diffa),(diffb))[1]}
⍝ Parameters
dt da db f k1.0 0.16 0.08 0.060 0.062
⍝ Initialization
N500
AN N1
B0.1×?N N0
B[((N÷2)-10)+20;((N÷2)-10)+20]1
⍝ Run
steps20000
Ap Bp(updatesteps)A B
⍝ ' ⌺'[Ap>0.5]
⍝ Export to image file
mat2pbm{'P1'(),¨>0.5} ⍝ black and white
mat2pgm{'P2'(),('255'),¨255×} ⍝ grayscale
(mat2pbm Ap)⎕NPUT'img.pnm'1