-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircleAnimation.m
More file actions
61 lines (51 loc) · 1.8 KB
/
CircleAnimation.m
File metadata and controls
61 lines (51 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
%% User Variables
% The total number of frames each sequence of dots should be animated for
NUM_FRAMES = 64;
% The maximum number of points that will be animated
MAX_POINTS = 7;
% A list containing the colors that the dots should animate through
COLORS = ["red", "green", "blue", "cyan", "magenta", "yellow", "black"];
%% Variable Validation
if MAX_POINTS < 1
error("MAX_POINTS must be greater than 1! Recieved %i instead.", MAX_POINTS)
end
if MAX_POINTS > length(COLORS)
error("MAX_POINTS is greater than length of provided COLORS! Please provide as many colors as points.")
end
%% Animation
frames = 1:NUM_FRAMES;
% Preallocating memomry
t = zeros(MAX_POINTS, NUM_FRAMES);
x = zeros(MAX_POINTS, NUM_FRAMES);
y = zeros(MAX_POINTS, NUM_FRAMES);
% Animation for each number of points to be shown
for num_points = 1:MAX_POINTS
%% Generate points
% An array to hold the index of each point
offset = 1:num_points;
spacing = num_points/2;
% The angle in radians that a point on the unit circle is at for each frame
for i = offset
t(i, frames) = linspace(-i*pi/spacing, 2*pi - (i*pi/spacing), NUM_FRAMES);
end
% Generate coordinates based on angle on the unit circle
x = cos(t);
y = sin(t);
%% Plot animation
for i = frames
scatter( ...
x(offset,i), ...
y(offset,i), ...
40, ...
COLORS(mod(i,num_points)+1), ... % Clamp the frame index to be within the bounds of COLORS
"o", ...
"filled" ...
)
hold("on")
% Set the axis bounds to be constant
axis([-10 10 -10 10])
% Make sure the animaton is momentarily visible
pause(0.0000001)
hold("off")
end
end