Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,80 @@
trunk = 1; //trunk length
ratio = 0.8; //size ratio between two consecutive branches
depth = 9; //final number of branch levels
orign = 0; //origin of the tree (should be complex)
angle = 45*%pi/180; //angle between two branches [rad]
trunk_angle = 90*%pi/180; //angle between trunk and X-axis [rad]
right_angle = angle/2; //angles to the right or to the left
left_angle = 0.8*angle; //can be set independently or
//as function of 'angle'
//L-system definition:
//Alphabet: FBD[]+-
//F: go forward B: go backwards
//[: start new branch ]: end current branch
//+: branch to the right -: branch to the left
//D: double line (forward then backward)
//Axiom: D
//Rule: D -> F[+D-D]B
//L-system sentence generation
sentence = 'D'
rule = 'F[+D-D]B';
for i=1:depth
sentence = strsubst(sentence,'D',rule);
end
sentence = strsplit(sentence)';
//Empty tree
tree_size = 1.0...
+ length(find(sentence=='F'|sentence=='B'))...
+ 2 * length(find(sentence=='D'));
tree=zeros(tree_size,1);
//Drawing the tree
branch_level = 0;
curr_angle = trunk_angle;
curr_pos = 1;
for ind = 1:size(sentence,'c')
charac = sentence(ind);
select charac
case 'F' then //Draw line forward
tree(curr_pos+1) = tree(curr_pos)...
+ trunk * ratio^branch_level * exp(curr_angle*%i);
curr_pos = curr_pos + 1;
case 'B' then //Draw line backwards
tree(curr_pos+1) = tree(curr_pos)...
+ trunk * ratio^branch_level * exp((%pi+curr_angle)*%i);
curr_pos = curr_pos + 1;
case '[' then //New branch
branch_level = branch_level + 1;
case '+' then //Turn right
curr_angle = curr_angle - right_angle;
case '-' then //Turn left
curr_angle = curr_angle + right_angle + left_angle;
case ']' then //End of branch
branch_level = branch_level - 1;
curr_angle = curr_angle - left_angle;
case 'D' then //Double line
tree(curr_pos+1) = tree(curr_pos)...
+ trunk * ratio^branch_level * exp(curr_angle*%i);
tree(curr_pos+2) = tree(curr_pos+1)...
+ trunk * ratio^branch_level * exp((%pi+curr_angle)*%i);
curr_pos = curr_pos + 2;
end
end
scf(); clf();
xname('Fractal tree: '+string(depth)+' levels')
plot2d(real(tree),imag(tree),14);
set(gca(),'isoview','on');
set(gca(),'axes_visible',['off','off','off']);

View file

@ -0,0 +1,17 @@
width = 512;
height = 512;
img=scf();
set(img,'figure_size',[width,height]);
function drawTree(x1, y1, angle, depth)
if depth ~= 0 then
x2 = x1 + cos(angle * %pi/180) * depth * 10;
y2 = y1 + sin(angle * %pi/180) * depth * 10;
plot2d([x1 x2],[y1 y2],14);
drawTree(x2, y2, angle - 20, depth - 1);
drawTree(x2, y2, angle + 20, depth - 1);
end
endfunction
drawTree(width/2,height,90,10);
set(gca(),'isoview','on');