Page 1 of 1

Fibonacci Spiral code

Posted: Wed Nov 27, 2024 2:29 pm
by amh

Code: Select all

% Spinning Fibonacci spiral
n = 500;
R = linspace(0,1,n);
T = 4/(1+sqrt(5))*pi*(1:n);
X = R.*cos(T);
Y = R.*sin(T);
newplot
tf = hgtransform;
scatter(tf,X,Y,R*30+10,R,'filled')
daspect([1 1 1])
axis off
speed = 0;
angle = 0;
for i = [1 2 3 4 3 2]
    speed = T(i); % Align with next point in spiral
    for k=1:150
        angle = angle+speed;
        tf.Matrix = makehgtform('zrotate',-angle);
        pause(1/120)
    end
end

Note: For older versions of MATLAB, adjust the scatter function to: scatter(X,Y,R*30+10,R,'filled','Parent',tf)
Image

Source: MATLAB Fb