• Remix
  • Share
  • New Entry

on 8 Oct 2024
  • 18
  • 191
  • 0
  • 4
  • 1172
Cite your audio source here (if applicable):
https://www.chosic.com/download-audio/27958/
drawframe(1);
Write your drawframe function below
function drawframe(f)
rng(0); % Keep background stationary
figure;
hold on;
axis off;
axis([-2 5 -5 6]);
% Background
fill([-2 5 5 -2], [-5 -5 6 6], [0 0 0.2]); % Dark sky
% Moon
theta = linspace(0, 2 * pi, 100);
r = 0.5;
x1 = 3 + r * cos(theta);
y1 = 4.5 + r * sin(theta);
fill(x1, y1, [1 1 1], 'EdgeColor', 'none');
% Ground
fill([-2 5 5 -2], [-5 -5 -2.5 -2.5], [0.1 0.5 0.1]); % Grass
% Trees
n_trees = 20;
for i = 1:n_trees
tx = rand * 7 - 2;
ty = -3.5;
th = rand * 2 + 1;
drawTree(tx, ty, th);
end
% Fireflies
n_fireflies = 30; % Increased number of fireflies
f_pos = [rand(n_fireflies, 1) * 7 - 2, rand(n_fireflies, 1) * 2 - 3];
for i = 1:n_fireflies
% Firefly movement in a circular pattern
angle = f * 0.05 + i; % Vary movement for each firefly
radius = 0.5 + 0.5 * sin(f * 0.1 + i); % Vary radius for a floating effect
fx = f_pos(i, 1) + radius * cos(angle);
fy = f_pos(i, 2) + radius * sin(angle);
bright = 0.7 + 0.3 * sin(2 * pi * (f / 100 + i / 10));
scatter(fx, fy, 200, [1, 1, 0] * bright, 'filled', 'MarkerEdgeColor', 'none', 'MarkerFaceAlpha', 0.9);
scatter(fx, fy, 500, [1, 1, 0] * bright, 'filled', 'MarkerEdgeColor', 'none', 'MarkerFaceAlpha', 0.4);
end
% Stars
sx = rand(30, 1) * 7 - 2;
sy = rand(30, 1) * 4 + 2;
scatter(sx, sy, 20, [1 1 1], 'filled'); % Stars
axis([-2 5 -5 6]);
drawnow;
end
% Function to draw a tree
function drawTree(x, y, h)
fill([x x+0.2 x+0.2 x], [y y y+h y+h], [0.6 0.3 0.1]); % Trunk
fill([x-0.6 x+0.1 x+0.8], [y+h y+h+0.6 y+h], [0.1 0.7 0.1]); % Leaves
fill([x-0.4 x+0.1 x+0.6], [y+h+0.4 y+h+1 y+h+0.4], [0.1 0.8 0.2]); % Extra foliage
end
Movie
Audio
Remix Tree