- /
-
Voronoi Cells
on 20 Nov 2023
- 15
- 79
- 2
- 0
- 351
drawframe(10);
Write your drawframe function belowfunction drawframe(f)
function drawframe(f)
persistent closest min_dist
if isempty(min_dist)
r=1000;
num=50;
points=randi(r,2,num);
p=complex(points(1,:),points(2,:));
[x,y]=meshgrid(1:r,1:r);
z=complex(x,y);
min_dist=ones(r)*Inf;
old_dist=min_dist;
closest=zeros(r);
for n=1:num
min_dist=min(min_dist,abs(z-p(n)));
closest(min_dist<old_dist)=n;
old_dist=min_dist;
end
end
im=closest;
im(min_dist>f*5)=51;
imshow(im*5,colorcube);
end