【发布时间】:2020-08-20 16:24:17
【问题描述】:
我有 50 个多边形。
多边形的属性在“pol”数组上,它们的几何形状在“dat”上。
在大约 10 秒的时间里,所有多边形都会经历 2 种颜色插值,同时它们会在屏幕上移动。
每个多边形从一种特定颜色开始,然后在大约 2 秒内内插成一种新颜色。
在结束前 2 秒,每个多边形插入第三种颜色
这是 Matlab 代码,我想用 swift 编写它。
我没有快速的经验,所以我必须学习动画。
我不希望您提供代码。
我想知道这是否可能,尤其是我暂停执行的部分。
如果你能给我一些参考资料甚至关键词来搜索它,也会有很大帮助。
谢谢
% Array with the geometry of the polygons
dat=zeros(10000,2);
% Array with the list of view updates
vlist=zeros(100,5);
% vlist(-,1) Graphics handle of the polygon
% vlist(-,2) Type of update, 1 geometry, 2 color
% vlist(-,3:5) Properties of update, either entries on dat or rgb color
% pol is an array with 50 rows and 18 columns
% There is a total of 50 polygons
% pol(-,1) Graphics handle of the polygon
% pol(-,2:3) Coordinates of the polygon on dat array
% pol(-,4:5) Motion animation, start and final step
% pol(-,6:7) Color interpolation 1, start and final step
% pol(-,8:9) Color interpolation 2, start and final step
% pol(-,10:12) Start rgb color of interpolation 1
% pol(-,13:15) Final rgb color of interpolation 1, also start of 2
% pol(-,16:18) Final rgb color of interpolation 2
t_tot=10; % Total time of the animation is seconds
fps=30; % Frames per second
dt=1/fps; % Time step in seconds
s_final=t_tot * fps; % Final step of the animation
for i=1:s_final
% Counter of updates to the polygons, either geometry or color
iv=0;
% Get the time at the start of the i step
time1=tic;
for j=1:50
% Update the geometry of the j polygon
if i>=pol(j,4) && i<=pol(j,5)
% Do some geometry calculations, translations,
% rotations, enlargements
% Add the geometry update to the update list
iv=iv+1; vlist(iv,1:5)=[pol(j,1), 1, pol(j,2:3), 0]
end
% Update the color of the j polygon, interpolation 1
if i>=pol(j,6) && i<=pol(j,7)
% Use the current step to interpolate the color
% Add the color update to the update list
iv=iv+1; vlist(iv,1:5)=[pol(j,1), 2, color]
end
% Update the color of the j polygon, interpolation 2
if i>=pol(j,8) && i<=pol(j,9)
% Use the current step to interpolate the color
% Add the color update to the update list
iv=iv+1; vlist(iv,1:5)=[pol(j,1), 2, color]
end
end
% Sent all updates to the view function
updateview(iv, vlist, dat)
% Get the time at the end of the i step
time2=toc;
% Calculate the remaining amount of time and pause execution
twait=dt-(time2-time1)
pause(twait)
end
【问题讨论】: