This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/plotting/code/movie_example.m

54 lines
1.2 KiB
Matlab

clear all
close all
max_frames = 500;
f_x = 1;
f_y = 1.5;
dt = 2*pi/500;
f = figure();
set(f, 'visible', 'off');
set(f, 'PaperUnits', 'centimeter', 'PaperSize', [2.5, 2.5], ...
'PaperPosition', [0, 0, 2.5, 2.5], 'Color', 'white')
writer = VideoWriter('../lecture/images/lissajous.mp4', 'MPEG-4');
writer.FrameRate = 25;
writer.Quality = 50;
open(writer);
for i = 1:max_frames
x = sin(f_x * 2 * pi * dt * i);
y = sin(f_y * 2 * pi * dt * i);
scatter(x, y, 30, 'r', 'filled');
xlim([-1.05, 1.05])
xticks([-1., 0., 1.])
ylim([-1.05, 1.05])
yticks([-1., 0., 1.])
xlabel('x')
ylabel('y')
drawnow;
frame = getframe(f);
writeVideo(writer, frame);
end
close(writer)
x_positions = zeros(max_frames, 1);
y_positions = zeros(max_frames, 1);
for i = 1:max_frames
x_positions(i) = sin(f_x * 2 * pi * dt * i);
y_positions(i) = sin(f_y * 2 * pi * dt * i);
end
f = figure();
set(f, 'PaperUnits', 'centimeter', 'PaperSize', [5, 5], ...
'PaperPosition', [0, 0, 5, 5], 'Color', 'white')
scatter(x_positions, y_positions, 10, 'r', 'filled');
xlim([-1.05, 1.05])
xticks([-1., 0., 1.])
ylim([-1.05, 1.05])
yticks([-1., 0., 1.])
xlabel('x')
ylabel('y')
saveas(f, '../lecture/images/lissajous.png')