create penrose tiling in matlab

main.m
% Define the 36 degree in radians
theta = 36*pi/180;

% Define the golden ratio
phi = (1 + sqrt(5))/2;

% Define the starting points
p1 = [0; 0];
p2 = [cos(theta); sin(theta)];

% Define the edge lengths
edge1 = 1;
edge2 = phi;

% Initialize a figure
fig = figure;
hold on;

% Draw the Penrose tiling
for i = 1:10
    [p1, p2] = penrose_step(p1, p2, edge1, edge2, theta);
    draw_line(p1, p2);
end

% Function to perform a Penrose step
function [q, r] = penrose_step(p, q, edge1, edge2, theta)
    r = p + edge1.*[cos(theta), sin(theta)]';
    p = q + edge2.*[cos(theta), sin(theta)]';
    q = r;
end

% Function to draw a line between two points
function draw_line(p, q)
    plot([p(1), q(1)], [p(2), q(2)], 'k');
end
720 chars
36 lines

This code will generate a Penrose tiling in MATLAB using a series of line segments. You can adjust the number of iterations by changing the loop in the code.

related categories

gistlibby LogSnag