From 9f8da9d348db0d8f5b193b68912dcb031bfd055c Mon Sep 17 00:00:00 2001 From: ShashiGowda Date: Mon, 9 Sep 2019 08:58:34 -0400 Subject: [PATCH 1/3] fix randomgrowth.jl --- demos/book/8/randomgrowth.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/demos/book/8/randomgrowth.jl b/demos/book/8/randomgrowth.jl index 445a056..158af90 100644 --- a/demos/book/8/randomgrowth.jl +++ b/demos/book/8/randomgrowth.jl @@ -12,7 +12,7 @@ function random_growth(M, N, q) sets = next_possible_squares(G) ## Highlights all the possible squares for i = 1:length(sets) - idx = sets[i]::(Int,Int) + idx = sets[i] G[idx[1], idx[2]] = 0.25 end display(imagesc((0,N), (M,0), G)) @@ -22,21 +22,21 @@ function random_growth(M, N, q) for i = 1:length(sets) ison = 0.5 * (rand() > (1-q)) if ison > 0 - idx = sets[i]::(Int,Int) + idx = sets[i] G[idx[1], idx[2]] = ison end end display(imagesc((0,N), (M,0), G)) - G[G .== 0.5] = 1 - G[G .== 0.25] = 0 + G[findall(G .== 0.5)] .= 1 + G[findall(G .== 0.25)] .= 0 sleep(.01) end return G end function next_possible_squares(G) - M, N = size(G)::(Int,Int) - sets = Array((Int,Int),0) + M, N = size(G) + sets = Array{Tuple{Int,Int}, 1}(undef, 0) for ii = 1:M for jj = 1:N if G[ii, jj] == 0 From acc39ed520efd943d64fc21472b2c4dba7634ffd Mon Sep 17 00:00:00 2001 From: ShashiGowda Date: Mon, 9 Sep 2019 09:01:50 -0400 Subject: [PATCH 2/3] more efficient findall --- demos/book/8/randomgrowth.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demos/book/8/randomgrowth.jl b/demos/book/8/randomgrowth.jl index 158af90..ea67cdb 100644 --- a/demos/book/8/randomgrowth.jl +++ b/demos/book/8/randomgrowth.jl @@ -27,8 +27,8 @@ function random_growth(M, N, q) end end display(imagesc((0,N), (M,0), G)) - G[findall(G .== 0.5)] .= 1 - G[findall(G .== 0.25)] .= 0 + G[findall(isequal(0.50), G)] .= 1 + G[findall(isequal(0.25), G)] .= 0 sleep(.01) end return G From 350f38d3448c3a8c88cb2b98c5436e92ea1eae94 Mon Sep 17 00:00:00 2001 From: ShashiGowda Date: Mon, 9 Sep 2019 10:39:03 -0400 Subject: [PATCH 3/3] use broadcast --- demos/book/8/randomgrowth.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demos/book/8/randomgrowth.jl b/demos/book/8/randomgrowth.jl index ea67cdb..58205d8 100644 --- a/demos/book/8/randomgrowth.jl +++ b/demos/book/8/randomgrowth.jl @@ -27,8 +27,8 @@ function random_growth(M, N, q) end end display(imagesc((0,N), (M,0), G)) - G[findall(isequal(0.50), G)] .= 1 - G[findall(isequal(0.25), G)] .= 0 + G[G .== 0.5] .= 1 + G[G .== 0.25] .= 0 sleep(.01) end return G