- /
-
Churn
on 10 Nov 2023
- 9
- 35
- 0
- 1
- 713
drawframe(1);
Write your drawframe function below
function drawframe(f)
% based on idea of slash and burn cultivation
n = 32; % size of land
area = 100; % cultivated land
decline_rate = 0.1; % rate of decline of cultivated land
recover_rate = 0.04; % rate of recovery
weight_random = 1; % random noise importance
weight_adjecency = 2; % adjacency importance
weight_inertia = 5; % inertia important
weight_suitability = 10; % suitability importance
warmup = 100;
skip = 5;
global suitability
global use
if f == 1
suitability = ones(n);
use = zeros(n);
for i = 1:warmup
step()
end
else
for i = 1:skip
step()
end
end
function step()
prox = conv2(use,[0 1 0; 1 0 1; 0 1 0 ],'same')> 0;
suitability(use==1) = suitability(use==1)*(1-decline_rate);
suitability(use==0) = 1 - (1- suitability(use==0))*(1-recover_rate);
pot = weight_suitability * suitability ...
+ weight_inertia * use ...
+ weight_adjecency * prox ...
+ weight_random * normrnd(0,1,n,n);;
[~,I] = maxk(pot(:),area);
use = use*0; use(I) = 1;
image(255*suitability); colormap(spring); axis equal; axis off
end
end