Demo entry 5862699

matlab

   

Submitted by anonymous on Aug 10, 2016 at 22:27
Language: Matlab. Code size: 706 Bytes.

clear;
clc;
filename='singif.gif';
x=0:0.1:10
y=sin(x);
x0=0;
y0=sin(x0); %定义小球初始坐标
plot(x,y);
grid on;
hold on;
Ball=plot(x0,y0,'.','MarkerSize',20);
xlabel('X');
ylabel('Y');
%通过循环把多个图片泄露GIF文件singif.gif
for i=1:1:100
    set(Ball,'xdata',x(i),'ydata',y(i));
    drawnow; %刷新屏幕
    pause(0.05);
    f=getframe(gcf); %抓取当前图形窗口中的图形作为一帧
    [IM,map]=frame2im(f); % 把抓取的帧转为图像数据
    if isempty(map)
    [IM,map]=rgb2ind(IM,256); %把真彩图像作为索引图像
    end
    if i==1
        %把第一幅图像写到GIF文件
        imwrite(IM,map,filename,'gif','Loopcount',inf,'DelayTime',0.01);
    else
        %把后续各个图像写道GIF文件
        imwrite(IM,map,filename,'gif','WriteMode','append','DelayTime',0.01);
    end
end

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).