Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,92 @@
side = 1; //side length of the square
depth = 8; //final number of branch levels
//L-system definition:
//Alphabet: UTDB+-[]
//U: go upwards T: top of the square
//D: go downwards B: bottom of the square
//[: start new branch ]: end current branch
//+: branch to the right -: branch to the left
//Axiom: UTDB
//Rule: T -> [+UTD-UTD]
//L-system sentence generation
sentence = 'UTDB'
rule = '[+UTD-UTD]';
for i=1:depth
sentence = strsubst(sentence,'T',rule);
end
sentence = strsplit(sentence)';
//Empty tree
tree_size = 1.0...
+ length(find(sentence == "U" | sentence == "T" |...
sentence == "D" | sentence == "B"))...
+ 2 * length(find(sentence == "]" | sentence == "-" |...
sentence == "+"));
tree=zeros(tree_size,1);
//Vectorial operation to calculate a new point in the tree
deff('z = new_point(origin,rho,theta)',...
'z = origin + rho * exp(%i*theta)');
//Drawing the tree
curr_angle = %pi/2;
curr_pos = 1;
ratio = 1/sqrt(2);
for ind = 1:size(sentence,'c')
charac = sentence(ind);
select charac
case 'U' then //Draw line upwards
tree(curr_pos+1) = new_point(tree(curr_pos),side,curr_angle);
curr_pos = curr_pos + 1;
case 'T' then //Draw top of the square
curr_angle = curr_angle - %pi/2;
tree(curr_pos+1) = new_point(tree(curr_pos),side,curr_angle);
curr_pos = curr_pos + 1;
case 'D' then //Draw line downwards
curr_angle = curr_angle - %pi/2;
tree(curr_pos+1) = new_point(tree(curr_pos),side,curr_angle);
curr_pos = curr_pos + 1;
case 'B' then //Draw the bottom
curr_angle = curr_angle - %pi/2;
tree(curr_pos+1) = new_point(tree(curr_pos),side,curr_angle);
curr_pos = curr_pos + 1;
case '[' then //Start branch
side = side * ratio;
case '+' then //Start going to the left
curr_angle = curr_angle - %pi/4;
// tree(curr_pos+1) = new_point(tree(curr_pos),side,curr_angle);
// tree(curr_pos+2) = new_point(tree(curr_pos+1),side,%pi+curr_angle);
// curr_pos = curr_pos + 2;
curr_angle = curr_angle + %pi/2;
case '-' then //Start going to the left
// tree(curr_pos+1) = new_point(tree(curr_pos),side,curr_angle);
// tree(curr_pos+2) = new_point(tree(curr_pos+1),side,%pi+curr_angle);
// curr_pos = curr_pos + 2;
curr_angle = curr_angle + %pi/2;
case ']' then
side = side / ratio;
curr_angle = curr_angle - %pi/4;
// tree(curr_pos+1) = new_point(tree(curr_pos),side,curr_angle);
// tree(curr_pos+2) = new_point(tree(curr_pos+1),side,%pi+curr_angle);
// curr_pos = curr_pos + 2;
curr_angle = curr_angle + %pi;
else
error('L-system sentence error');
end
end
scf(); clf();
xname('Pythagoras 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,29 @@
function []=fcn(bitmap,ax,ay,bx,by,depth)
if depth < 0 then
return
end
dx = bx - ax; dy = ay - by;
x3 = bx + dy; y3 = by + dx;
x4 = ax + dy; y4 = ay + dx;
x5 = x4 + (dx + dy)/2; y5 = y4 + (dx - dy)/2;
scf(bitmap);
plot2d([x3 x4 x5],[y3 y4 y5],-2)
plot2d([ax bx],[ay by]); plot2d([bx x3],[by y3]);
plot2d([x3 x4],[y3 y4]); plot2d([x4 ax],[y4 ay]);
fcn(bitmap,x4,y4,x5,y5,depth-1);
fcn(bitmap,x5,y5,x3,y3,depth-1);
endfunction
plot_win = scf();
final_depth = 8;
clf();
fcn(plot_win,275,500,375,500,final_depth)
scf(plot_win);
xname('Pythagoras tree: '+string(final_depth)+' levels');
set(gca(),'isoview','on');
set(gca(),'axes_visible',['off','off','off']);