Question: 1) Write a Matlab script to create a movie with the stipulations below. Feel free to use the script we created in class together as
1) Write a Matlab script to create a movie with the stipulations below. Feel free to use the script we created in class together as a template. The base shape is a polygon.
The size of your polygon monotonically decreases, but never actually disappears, even if you let t get really large. (t is the time on the timer).
Your polygon moves from the upper left part of the screen to the lower right part of the screen. The polygon rocks back and forth, back and forth, similar to a pendulum. You need to include a timer, as demonstrated in class.
The Code we made in class is below:
clear; clf;
%dimensions for window xmin = -350; xmax = 350; ymin = -350; ymax = 350; bounds = [xmin xmax ymin ymax];
%time stuff tmin = 0; tmax = 6; dt = 0.01; %delta t = dt t = [tmin : dt : tmax]; %start at tmin, incriments of dt, end at tmax tlevels = length(t); %amount of stills (frames)
%where to display timer xtxt = 200; ytxt = 200;
%starting shape x = [1 0 -1 0 1]; y = [0 1 0 -5 0]; %plot(x,y); %shows a diamond shape
%scaling factor sf = @(t) 10*log(t+1);
%translation terms xtrans = @(t) 100*cos(2*t); ytrans = @(t) 100*sin(2*t);
%rotation stuff (makes it spin) alpha = @(t) t^3; R = @(theta) [cos(theta) sin(theta) -sin(theta) cos(theta)];
A = [x y]';
for i = 1:tlevels Anew = sf(t(i))*A*R(alpha(t(i))); x = Anew(:,1) + xtrans(t(i)); y = Anew(:,2) + ytrans(t(i)); plot(x,y,'m'); fill(x,y,'m'); axis('equal'); axis(bounds); ttext = strcat('t = ', num2str(t(i))); text(xtxt, ytxt, ttext); M(i) = getframe(); end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
