function virus_spread_viz()
[X,Y,Z,Q] = get_earth_surface();
%C = get_surf_color(Q);
C = get_surf_color_random(Q);
clf
[xx,yy,zz] = get_curved_lines();
hLine = zeros(size(xx,1),1);
for i=1:numel(hLine)
hLine(i) = line(xx(i,:),yy(i,:),zz(i,:), 'Color','m', ...
'LineWidth',2, 'LineStyle','-');
end
hTxt = text(9,20,3.5, '', 'BackgroundColor',[.7 .9 .7]);
hSurf = surface('XData',X, 'YData',Y, 'ZData',Z.*0.5, ...
'CData',C);
axis tight; grid on; box on; view(-15,30)
zlim([0 6]); %axis([1 40 1 20 0 10])
for i=1:100
C = get_surf_color_random(Q);
set(hSurf, 'CData',C)
set(hLine(1), 'Visible',get_visibility())
set(hLine(2), 'Color',rand(1,3))
set(hLine(3), 'LineWidth',randi([1,5]))
set(hTxt, 'String',get_string_random())
drawnow
pause(0.1)
end
end
function [X,Y,Z,Q] = get_earth_surface()
% lets create earth surface (X/Y/Z coords)
[X,Y] = meshgrid(1:20,1:40);
% continents
Q = zeros(size(X));
Q(20:35,3:7) = 1; % north america
Q(5:10,5:7) = 2; % south america
Q(7:17,10:14) = 3; % africa
Q(21:33,11:18) = 4; % europe
Q(9:12,17:19) = 5; % australia
Z = zeros(size(X));
Z(Q>0) = 1;
end
function C = get_surf_color_random(Q)
sz = [40,20];
C_r = zeros(sz);
C_g = zeros(sz);
C_b = ones(sz);
for i=1:5
C_r(Q==i) = rand();
C_g(Q==i) = rand();
C_b(Q==i) = rand();
end
C = cat(3, C_r,C_g,C_b);
end
function [x,y,z] = get_curved_lines()
t = linspace(1,3,30);
x = zeros(3,30);
y = zeros(3,30);
z = zeros(3,30);
% [7,7,0] -> [15,30,0]
x(1,:) = spline(1:3, [7,11,15], t);
y(1,:) = spline(1:3, [7,18.5,30], t);
z(1,:) = spline(1:3, [0,2,0], t);
% [5,30,0] -> [13,10,0]
x(2,:) = spline(1:3, [5,9,13], t);
y(2,:) = spline(1:3, [30,20,10], t);
z(2,:) = spline(1:3, [0,3,0], t);
% [18,10,0] -> [16,26,0]
x(3,:) = spline(1:3, [18,17,16], t);
y(3,:) = spline(1:3, [10,18,26], t);
z(3,:) = spline(1:3, [0,2,0], t);
end
function str = get_string_random()
alpha = 'a':'z';
str = alpha(randperm(numel(alpha),randi([4 10])));
end
function vis = get_visibility()
states = {'on','off'};
vis = states{randi(numel(states))};
end