Created
September 19, 2018 11:57
-
-
Save SoTaInverSpinel/c4718dd4c3b7de5f243a917838be5015 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#BZ-reaction | |
#reference:http://discovery.ucl.ac.uk/17241/1/17241.pdf | |
#julia v0.6 | |
using Plots | |
gr(size=(320,300)) | |
h=400 | |
w=400 | |
α=1.2 | |
β=1.0 | |
γ=1.0 | |
a=rand(h,w) | |
b=rand(h,w) | |
c=rand(h,w) | |
tempa=zeros(h,w) | |
tempb=zeros(h,w) | |
tempc=zeros(h,w) | |
function update() | |
tempa.=a | |
tempb.=b | |
tempc.=c | |
for x=1:h,y=1:w | |
ca=0.0 | |
cb=0.0 | |
cc=0.0 | |
for i =(x-1):(x+1),j=(y-1):(y+1) | |
if i<1; i=h-i; end | |
if i>h; i=i-h; end | |
if j<1; j=w-j; end | |
if j>w; j=j-w; end | |
ca+=tempa[i,j] | |
cb+=tempb[i,j] | |
cc+=tempc[i,j] | |
end | |
ca/=9.0 | |
cb/=9.0 | |
cc/=9.0 | |
a[x,y]=ca+ca*(α*cb-γ*cc) | |
b[x,y]=cb+cb*(β*cc-α*ca) | |
c[x,y]=cc+cc*(γ*ca-β*cb) | |
end | |
a.=clamp.(a,0.0,1.0) #broadcast | |
b.=clamp.(b,0.0,1.0) | |
c.=clamp.(c,0.0,1.0) | |
end | |
@time anim = @animate for t in 0:100 | |
heatmap(a, | |
title="t= $t", | |
aspect_ratio=:equal | |
) | |
update() | |
end | |
@time gif(anim,"tmp/BZreaction3.gif",fps=5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment