Skip to content

Commit

Permalink
Masser af gode ting
Browse files Browse the repository at this point in the history
  • Loading branch information
TadeaVeng committed Nov 10, 2016
1 parent 7183782 commit e6c8fa0
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
30 changes: 30 additions & 0 deletions LindIter.m
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

37 changes: 37 additions & 0 deletions turtleGraph.m
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
46 changes: 46 additions & 0 deletions turtlePlot.m
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











1 comment on commit e6c8fa0

@KurisuDaNoda
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely beautiful 🤘

Please sign in to comment.