Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix randomgrowth.jl #50

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions demos/book/8/randomgrowth.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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[G .== 0.5] .= 1
G[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
Expand Down