-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
% Lindenmayer Iteration | ||
|
||
function LindenmayerString = LindIter(System,N) | ||
|
||
% Hvis Koch systemet vælges laves følgende erstatning | ||
if strcmpi(System,'koch') | ||
ko='S'; | ||
for i=1:N | ||
ko = strrep(ko,'S','SLSRSLS'); | ||
end | ||
LindenmayerString=ko; | ||
|
||
% Hvis Sierpinski | ||
elseif strcmpi(System,'sierpinski') | ||
si='A'; | ||
for i=1:N | ||
% Der laves hjælpestrings for at undgå "dobbelterstatning" | ||
si = strrep(si,'A','T'); | ||
si = strrep(si,'B','P'); | ||
si = strrep(si,'T','BRARB'); | ||
si = strrep(si,'P','ALBLA'); | ||
end | ||
LindenmayerString=si; | ||
|
||
%Afslut if-statement | ||
end | ||
|
||
% Afslut funktion | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function turtleCommands = turtleGraph(LindenmayerString) | ||
|
||
NumberOfL = sum( LindenmayerString == 'S'); | ||
NumberOfA = sum( LindenmayerString == 'A'); | ||
NumberOfB = sum( LindenmayerString == 'B'); | ||
% An if statement to determine the type of system | ||
turtleCommands=zeros(1, length(LindenmayerString)); | ||
|
||
if NumberOfL >0 && (NumberOfA== 0 && NumberOfB== 0) | ||
|
||
Iteration = (1+log(NumberOfL)/log(4)); | ||
Length = (1/3)^(Iteration-1); | ||
|
||
turtleCommands(LindenmayerString == 'S') = Length; | ||
turtleCommands(LindenmayerString == 'L') = 2*pi/6; | ||
turtleCommands(LindenmayerString == 'R') = -4*pi/6; | ||
|
||
disp(turtleCommands) | ||
elseif NumberOfA >0 && NumberOfB > 0 && NumberOfL == 0 | ||
|
||
|
||
Iteration = input('Iteration no:') | ||
|
||
Length = (1/2)^(Iteration-1); | ||
|
||
turtleCommands(LindenmayerString == 'A') = Length; | ||
turtleCommands(LindenmayerString == 'B') = Length; | ||
turtleCommands(LindenmayerString == 'L') = 2*pi/6; | ||
turtleCommands(LindenmayerString == 'R') = -2*pi/6; | ||
disp(turtleCommands) | ||
|
||
else | ||
|
||
disp('invalid system') | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
% Turtle grafics plot function | ||
|
||
function turtlePlot(turtleCommands) | ||
% Længderne samles i vektoren R | ||
% Dette gøres ved angtagelse om at alle længder er ens | ||
L=0.5*(length(turtleCommands)+1); | ||
V=ones(1,L); | ||
r=turtleCommands(1)*V; | ||
|
||
% Vinklerne samles i vektoren theta | ||
LtC=(0.5*(length(turtleCommands)-1)); | ||
for i=1:(LtC+2) | ||
turtleCommands(i*2-1)=false; | ||
end | ||
theta=turtleCommands(turtleCommands~=false); | ||
theta=[0 0 theta]; | ||
r=[0 r]; | ||
theta=cumsum(theta); | ||
|
||
% Der omskrives fra polær til katetisk | ||
x=ones(1,length(r)); | ||
y=ones(1,length(r)); | ||
for i=1:length(r) | ||
x(i)=r(i)*cos(theta(i)); | ||
y(i)=r(i)*sin(theta(i)); | ||
|
||
end | ||
|
||
x=cumsum(x); | ||
y=cumsum(y); | ||
plot(x,y) | ||
|
||
|
||
% Afslut funktion | ||
end | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
e6c8fa0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely beautiful 🤘