Swift中的低级动画

Swift中的低级动画,swift,animation,low-level,Swift,Animation,Low Level,我有50个多边形。 多边形的属性位于“pol”阵列上,其几何图形位于“dat”上。 在大约10秒钟内,所有多边形都会进行2次颜色插值,同时它们会在屏幕上移动。 每个多边形从一种特定的颜色开始,然后插值为一种新颜色,持续约2秒。 在结束前2秒,每个多边形插值为第三种颜色 这是Matlab代码,我想用swift编写。 我没有敏捷的经验,所以我必须学习动画。 我不希望您提供代码。 我想知道这是否可行,尤其是我暂停执行的部分。 如果你能给我一些参考资料,甚至是关键词来搜索它,这也会有很大帮助。 多谢各位

我有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
%包含多边形几何体的数组
dat=零(10000,2);
%包含视图更新列表的数组
vlist=零(100,5);
%多边形的vlist(-,1)图形句柄
%vlist(-,2)更新类型,1个几何体,2个颜色
%更新的vlist(-,3:5)属性,dat或rgb颜色上的条目
%pol是一个50行18列的数组
%总共有50个多边形
%多边形的pol(-,1)图形控制柄
%dat阵列上多边形的pol(-,2:3)坐标
%pol(-,4:5)运动动画,开始和最后一步
%pol(-,6:7)颜色插值1,开始和结束步骤
%pol(-,8:9)颜色插值2,开始和结束步骤
%pol(-,10:12)开始插值1的rgb颜色
%pol(-,13:15)插值1的最终rgb颜色,也是插值2的开始
%pol(-,16:18)插值2的最终rgb颜色
t_tot=10;%动画的总时间为秒
fps=30;%每秒帧数
dt=1/fps;%时间步长(秒)
s_final=t_tot*fps;%动画的最后一步
对于i=1:s_决赛
%多边形(几何体或颜色)更新计数器
iv=0;
%获取i步骤开始时的时间
时间1=抽搐;
对于j=1:50
%更新j多边形的几何图形

如果i>=pol(j,4)&&i=pol(j,6)&&i=pol(j,8)&&i幸运的是,苹果提供了用于管理二维甚至三维图形的即插即用解决方案。我猜你的新朋友可能是“SpriteKit”,其中2D的东西,如移动精灵、制作粒子效果、调整大小和移动动画是基本部分。它已经包含了许多针对iOS/iPadOS设备的后台优化

苹果解决方案的3D版本是SceneKit

您还可以通过使用金属来“低级别”访问GPU


您也可以查看一些第三方库,但我认为这些是在iOS/iPadOS上使用的方法。(除了Unity、Unreal等引擎)

幸运的是,苹果提供了管理2D甚至3D图形的即插即用解决方案。我猜你的新朋友可能是“SpriteKit”,其中2D的东西,如移动精灵、制作粒子效果、调整大小和移动动画是基本部分。它已经包含了许多针对iOS/iPadOS设备的后台优化

苹果解决方案的3D版本是SceneKit

您还可以通过使用金属来“低级别”访问GPU

您也可以查看一些第三方库,但我认为这些是在iOS/iPadOS上使用的方法。(除了统一、不真实等引擎)