- /
-
Spinning
on 11 Nov 2023
- 7
- 21
- 2
- 0
- 1844
function drawframe(f)
% draw the grid
x1=0:DX*2:8*DY;
g(x1, 0:DY:DY*8);
hold on
g(x1(1:end-1) + DX, 10:DY:DY*8);
% run one of the 4 sequences
if f <=17
s1(f)
elseif f<=25
s2(f);
elseif f<=40
s3(f);
else
s4(f);
end
% axis adjustments
xlim([0 160])
ylim([0 160])
axis off
hold off
end
function r = DX
r = sin(deg2rad(60)) * DY;
end
function r = DY
r = 20;
end
function r = P
r = [1 0 .5];
end
function r = G
r = [0 .8 .8];
end
function [x,y] = getXY(i,j)
x = i * DX;
y = j * DY + (mod(i, 2) == 1) * DY/2;
end
function g(x, y)
[X, Y] = meshgrid(x, y);
scatter(X, Y, MarkerEdgeColor=[.5 .5 .5]);
end
function l(i,j,k,cw,c)
dy = 10;
[ox, oy] = getXY(i,j);
if cw == 0
k = 360 - k;
end
a = deg2rad(k);
x = [ox ox+sin(a)*dy*2];
y = [oy oy+cos(a)*dy*2];
plot(x,y, Color=c)
end
function s1(f)
f = (f-1)/8;
for p = [0 0 4 4 4 8 8 ;
2 6 0 4 8 2 6]
for i=0:5
l(p(1), p(2), (f+i) * 60, 0, P)
end
end
for p = [0 0 0 4 4 8 8 8 0 0 0 4 4 8 8 8 2 2 6 6 2 2 6 6 2 2 6 6 2 2 6 6;
0 4 8 2 6 0 4 8 0 4 8 2 6 0 4 8 1 5 3 7 1 5 3 7 3 7 1 5 3 7 1 5;
0 0 0 0 0 0 0 0 3 3 3 3 3 3 3 3 2 2 2 2 5 5 5 5 1 1 1 1 4 4 4 4]
l(p(1), p(2), (f+p(3)) * 60, 1, G)
end
end
function s2(f)
f = (f-1)/8;
pink(f, 2);
green(f, 2);
end
function s3(f)
f = (f-1)/8;
pink(f, 3);
green(f, 3);
end
function s4(f)
f = (f-1)/8;
pink(f, 4);
for p = [0 0 0 0 1 1 1 1 3 3 3 3 4 4 4 4 5 5 5 5 7 7 7 7 8 8 8 8;
1 3 5 7 1 2 5 6 0 3 4 7 1 3 5 7 0 3 4 7 1 2 5 6 1 3 5 7;
3 0 3 0 2 1 2 1 5 4 5 4 0 3 0 3 1 2 1 2 4 5 4 5 3 0 3 0]
l(p(1), p(2), (f+p(3)) * 60, 1, G)
end
end
function green(f,m)
if m == 2
v = [5 3 5 3 4 1 4 1 2 0 2 0 3 5 3 5 4 1 4 1 0 2 0 2];
else
v = [0 4 0 4 5 2 5 2 3 1 3 1 4 0 4 0 5 2 5 2 1 3 1 3];
end
for p = [1 1 1 1 2 2 2 2 3 3 3 3 5 5 5 5 6 6 6 6 7 7 7 7;
0 3 4 7 2 4 6 8 1 2 5 6 1 2 5 6 0 2 4 6 0 3 4 7; v]
l(p(1), p(2), (f+p(3)) * 60, 1, G)
end
end
function pink(f, m)
if m == 2
v = [3 2 4 1 5 0];
elseif m == 3
v = [1 0 2 5 3 4];
else
v = [5 4 0 3 1 2];
end
for p = [0 0 4 4 4 8 8;
2 6 0 4 8 2 6]
for i = [ -1 -1 0 0 1 1;
-1 0 -1 1 -1 0; v]
l(p(1)+i(1), p(2)+i(2), (f+i(3)) * 60, 0, P)
end
end
end