- /
-
BLACK HOLE
on 17 Oct 2024
- 9
- 68
- 0
- 0
- 1993
Cite your audio source here (if applicable):
drawframe(1);
Write your drawframe function below
function drawframe(f)
numPlanets = 10;
frames = 150;
totalTime = 5;
timePerFrame = totalTime / frames;
blackHolePosition = [0, 0];
% Create figure window
figure;
hold on;
axis([-200 200 -200 200]);
axis off;
set(gcf, 'Color', 'k');
text(blackHolePosition(1), blackHolePosition(2) + 20, 'Black Hole', ...
'Color', 'w', 'FontSize', 16, 'FontWeight', 'bold', 'HorizontalAlignment', 'center');
numStars = 200;
starX = randi([-200, 200], 1, numStars);
starY = randi([-200, 200], 1, numStars);
starSizes = randi([2, 6], 1, numStars); % Random star sizes
scatter(starX, starY, starSizes, 'w', 'filled'); % Shiny white stars
planetPositions = [
-150, 100; -100, -120; 120, 150;
160, -100; -130, -160; 100, 100;
-90, 130; 150, 50; -120, -50;
50, -170
];
planetVelocities = zeros(numPlanets, 2);
for i = 1:numPlanets
direction = blackHolePosition - planetPositions(i, :);
direction = direction / norm(direction); % Normalize
planetVelocities(i, :) = direction * (6 + rand() * 4); % Initial speed between 6 and 10
end
blackHole = plot(blackHolePosition(1), blackHolePosition(2), 'wo', ...
'MarkerSize', 20, 'MarkerFaceColor', 'k', 'LineWidth', 2);
planets = gobjects(1, numPlanets);
for i = 1:numPlanets
planets(i) = plot(planetPositions(i,1), planetPositions(i,2), 'o', ...
'MarkerSize', 8, 'MarkerFaceColor', rand(1, 3), ...
'MarkerEdgeColor', 'none');
end
% Stronger Gravity function
gravity = @(p, bh) -15 * (p - bh) ./ norm(p - bh)^2.5; % Base gravitational pull
% Animation loop
for k = 1:frames
% Update star brightness
if mod(k, 5) == 0
newStarColors = rand(numStars, 1) * 0.5 + 0.5; % Random brightness
scatter(starX, starY, starSizes, newStarColors, 'filled'); % Update stars
end
for i = 1:numPlanets
distance = norm(planetPositions(i,:) - blackHolePosition);
if distance >= 10 && ishandle(planets(i))
attraction = gravity(planetPositions(i,:), blackHolePosition);
planetVelocities(i,:) = planetVelocities(i,:) + attraction * timePerFrame;
planetPositions(i,:) = planetPositions(i,:) + planetVelocities(i,:) * timePerFrame;
set(planets(i), 'XData', planetPositions(i,1), 'YData', planetPositions(i,2));
elseif distance < 10
set(planets(i), 'Visible', 'off'); % Make the planet disappear
end
end
end
% Add end message
text(0, -30, 'You know what happens next ⚠️', ...
'Color', 'r', 'FontSize', 12, 'FontWeight', 'bold', ...
'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle');
hold off;
end