This GitHub project was a collaborative effort to create a captivating animated story using MATLAB. Each contributor was responsible for a specific part of the animation, adding unique motions and transformations to bring the story to life. The images used in this project were represented as large matrices of coordinate points, generated by a program created by our professor (program and coordinate points not included). These matrices served as the foundation for the animation, with mathematical transformations applied to the points to achieve various visual effects and create a animated storytelling experience.
- Motion 1: Jack o’lantern morphs into the witch
- Motion 2: Magic book appears, flies to the cauldron, and spins into it
- Motion 3: Cauldron stirs magically
- Motion 1: Mouse flies out of the pot
- Motion 2: Witch and mouse chase each other
- Motion 3: Mouse and witch run off the screen My code is saved as witch_animation.m in the repo.
- Both characters run left on the screen
- Witch casts a spell, oscillating with the wand
- Mickey Mouse morphs into a ghost, then the ghost flies away
- Zoom out to the whole world
- Fly around the world
- Land in the North Pole
- Character lands in the North Pole
- Background changes to the North Pole with a ghost in the scene
- Character turns into a gingerbread man
- Display a "Happy Holiday" sign
The project utilizes several MATLAB functions for transformations and animations:
[matrix] = sheer(matrix, sheerfactor)
[matrix] = rotation(matrix, degree)
[matrix] = shift(matrix, steps/direction)
- Positive steps move right, negative steps move left
function [A, B, M] = morph(A, B, M)
function [A, B, M] = morph(A, B, M)
% Morph input A into B with an option to translate with an additional matrix M.
% If you don't intend to translate, make M the identity matrix.
N = A;
[Br, Bc] = size(B);
[Ar, Ac] = size(A);
if (Bc < Ac)
Dif = abs(Ac - Bc);
Z = zeros(3, Dif);
B = [B Z];
else
Dif = abs(Bc - Ac);
Z = zeros(3, Dif);
A = [A Z];
end
for k = 0:1/20:1
P = (1 - k) * B + k * A;
P = M * P;
plot(P(1, :), P(2, :), '.')
pause(0.1);
plot(P(1, :), P(2, :), '.', 'color', 'w')
end
end
- Morphs input A into B with the option to translate using an additional matrix M
- If no translation is intended, set M as the identity matrix
function [newrat, A] = Move(N, A)
function [newrat, A] = move(N, A)
% Takes in a set of points and a matrix, moves it to the center,
% multiplies by matrix, then moves back.
[Nr, Nc] = size(N);
Ax = 0;
Ay = 0;
for i = 1:Nc
Ax = Ax + N(1, i);
Ay = Ay + N(2, i);
end
Ax1 = Ax / Nc;
Ay1 = Ay / Nc;
N1 = [1 0 -Ax1; 0 1 -Ay1; 0 0 1] * N;
N2 = A * N1;
N3 = [1 0 Ax1; 0 1 Ay1; 0 0 1] * N2;
A = A; % Note: It seems A is not being modified in this function, you may want to check if this assignment is necessary.
newrat = N3;
end
- Takes in a set of points and a matrix, moves it to the center, multiplies by the matrix, and moves back to the original position.
Feel free to use this template and provided code to create your own animated holiday story!