- /
-
Disco Ball!
on 7 Oct 2024
- 11
- 149
- 0
- 0
- 538
Cite your audio source here (if applicable):
https://pixabay.com/users/vibestreamfree-45978831/
drawframe(1);
function drawframe(f)
% Parameters
N = 600; % Size of the grid
[X0, Y0] = meshgrid(linspace(-1, 1, N)); % Create a grid for the ball
R0 = sqrt(X0.^2 + Y0.^2); % Radius from center
t = 2 * pi * f / 96; % Time variable for rotation
phi = t; % Rotation angle
% Calculate the positions for the ball
Z0 = sqrt(1 - R0.^2); % Z values for a unit sphere
Z0(isnan(Z0)) = 0; % Handle NaN values to avoid coverage issues
X = X0 * cos(phi); % Rotation around Y-axis for side view
Y = Y0; % No rotation along X-axis for side view
Z = Z0; % Z stays the same for the sphere
% Colors and brightness patterns
numColors = 12; % Number of LED colors
colors = hsv(numColors); % Generate colors using HSV colormap
img = ones(N, N, 3); % Initialize image with a white background
% Assign dynamic colors and brightness to the ball
for i = 1:N
for j = 1:N
if R0(i,j) <= 1 % Ensure we stay within the spherical boundary
angle = atan2(Y(i,j), X(i,j)); % Angle for color selection
colorIndex = mod(floor(angle * numColors / (2 * pi)), numColors) + 1;
brightness = 0.5 + 0.5 * sin(t + R0(i,j) * 4); % Dynamic brightness effect
% Avoid black coverage by ensuring brightness is always above 0
img(i,j,:) = colors(colorIndex, :) * max(brightness, 0.2); % Minimum brightness threshold
end
end
end
% Normalize values between 0 and 1
img = min(max(img, 0), 1);
% Display the image of the disco ball
imshow(img, 'InitialMagnification', 'fit');
axis off; % Remove axis lines
end


