问题描述
我正在尝试创建一个球或点或从左下角到右下角,然后是右上角,然后是左上角,然后是起点的任何东西。基本上在屏幕周围。而且在全屏模式下那很重要。对于全屏图形,我正在使用WindowAPI。
这是我的代码。
try
% Create a figure to operate on: --------------------------------------------
% The OpenGL renderer is confused by the alpha blending,so Painters is used:
figH = figure('Color',ones(1,3),'Renderer','Painters');
axes('Visible','off','Units','normalized','Position',[0,1,1]);
% Set topmost status:
WindowAPI(figH,'topmost'); % Command is not case-sensitive
drawNow;
WindowAPI(figH,'TopMost',0);
drawNow;
WindowAPI(figH,'front');
drawNow;
% Nicer to have the figure on topmost for the rest of the demo:
WindowAPI(figH,'topmost');
% Special maximizing such that the inner figure fill the screen:
WindowAPI(figH,'full'); % Complete monitor
% START MOVING BALL
X = 2;
Y = 0;
for i=1:1490
X = X + 0.1;
Y = 2
plot(X,Y,'or','MarkerSize',20,'MarkerFaceColor','r')
axis([0 151 0 85])
pause(0)
end
% END MOVING BALL
end
为简单起见,点仅从左下角到右下角。 但是有两个问题。
- 有时候点滞后是一个问题。
- (从图中)有可见的黑线。
我不知道如何解决这两个问题。因此,如果您知道如何修复它们或以任何更好的方式在Matlab中为球设置动画,请在此处发布。谢谢您的时间。
解决方法
要减少“滞后”量,您可以执行以下操作:
-
将绘图线移动到循环的外部,并将其分配给手柄,另外将轴突击移动到一起
pH = plot(X,Y,'or','MarkerSize',20,'MarkerFaceColor','r'); axis([0 151 0 85]) axis off
现在您可以直接在循环中更新X Y数据。
set(pH,'XData',X,'YData',Y)
-
将暂停替换为(将延迟帧的秒数长度替换为0):
tic;while toc<0;end
这更快,更精确,并且不会导致MatLab中断。
-
在循环中添加
drawnow
命令以使图形更新。