- /
-
WindMill
on 15 Oct 2024
- 16
- 127
- 0
- 0
- 1405
Cite your audio source here (if applicable):
drawframe(1);
Write your drawframe function below
function drawframe(f)
nB = 3; bL = 5; tH = 6; gL = -4; rSp = 5;
figure; hold on; axis([-10 10 gL 10]); set(gca, 'Color', [0.529 0.808 0.922]);
fill([-10 10 10 -10], [gL gL -2 -2], [0.13 0.55 0.13]);
fill([-1 1 1 -1] + 1, [gL gL tH+gL tH+gL], [0.8 0.8 0.8]);
fill([-0.5 0.5 0]*2 + 1, [tH+gL tH+gL tH+2+gL], [1 0 0]);
b = [-bL 0; bL 0; bL 0.5; -bL 0.5]; % Blades
c = lines(nB); bl = gobjects(1, nB);
for i = 1:nB
rA = (i-1) * 360 / nB;
rM = [cosd(rA) -sind(rA); sind(rA) cosd(rA)];
rB = (rM * b')';
bl(i) = patch(rB(:,1)+1, rB(:,2) + tH + gL, c(i,:), 'EdgeColor', 'none');
end
% Sun
sun = rectangle('Position', [7.5, 7.5, 1.6, 1.6], 'Curvature', [1, 1], 'FaceColor', [1 1 0.5], 'EdgeColor', 'none');
for i = 1:12
angle = (i-1) * 30;
rX = [cosd(angle) cosd(angle)] * 3;
rY = [sind(angle) sind(angle)] * 3;
line([8.3 8.3 + rX], [8.3 8.3 + rY], 'Color', [1 1 0], 'LineWidth', 2);
end
birdX = [-0.5 0.5 0] * 0.8;
birdY = [0 0 -0.5] * 0.8;
bird_positions = [-9 8; -5 8.5; -3 8.7];
for i = 1:3
fill(bird_positions(i,1) + birdX, bird_positions(i,2) + birdY, 'k', 'EdgeColor', 'none');
end
tic; startTime = toc; duration = 2;
while toc - startTime < duration
rM = [cosd(rSp) -sind(rSp); sind(rSp) cosd(rSp)];
for i = 1:nB
if isvalid(bl(i))
x = get(bl(i), 'XData') - 1;
y = get(bl(i), 'YData') - tH - gL;
newC = rM * [x'; y'];
set(bl(i), 'XData', newC(1,:) + 1, 'YData', newC(2,:) + tH + gL);
end
end
if mod(toc - startTime, 1) < 0.5
set(sun, 'FaceColor', [1 1 0.8]);
else
set(sun, 'FaceColor', [1 0.6 0.3]);
end
drawnow;
end
end