Fixed docs formating and code indentation.

This commit is contained in:
Revar Desmera 2019-07-14 12:30:46 -07:00
parent c6f4f7c586
commit a89edec667

View file

@ -584,7 +584,8 @@ module supershape(step=0.5,m1=4,m2=undef,n1,n2=undef,n3=undef,a=1,b=undef, r=und
// path = turtle(flatten(replist(["move","left",144],10)));
// stroke(path,width=.05);
// Example(2d): Sawtooth path
// path = turtle(["turn", 55,
// path = turtle([
// "turn", 55,
// "untily", 2,
// "turn", -55-90,
// "untily", 0,
@ -599,7 +600,8 @@ module supershape(step=0.5,m1=4,m2=undef,n1,n2=undef,n3=undef,a=1,b=undef, r=und
// ]);
// stroke(path, width=.1);
// Example(2d): Simpler way to draw the sawtooth. The direction of the turtle is preserved when executing "yjump".
// path = turtle(["turn", 55,
// path = turtle([
// "turn", 55,
// "untily", 2,
// "yjump", 0,
// "untily", 2.5,
@ -639,12 +641,13 @@ function turtle(commands, state=[[[0,0]],[1,0],90], full_state=false) =
_turtle(commands,state,full_state);
function _turtle(commands, state, full_state, index=0) =
index < len(commands) ? _turtle(commands,
index < len(commands) ?
_turtle(commands,
turtle_command(commands[index],commands[index+1],state,index),
full_state,
index+(!is_string(commands[index+1])?2:1)
)
: ( full_state ? state : state[0] );
) :
( full_state ? state : state[0] );
// Turtle state: state = [path, step_vector, default angle]
@ -666,21 +669,24 @@ function turtle_command(command, parm, state, index) =
assert(chnum,str("\"",command,"\" requires a numeric parameter at index ",index))
assert(vec_or_num,str("\"",command,"\" requires a vector or numeric parameter at index ",index))
command=="move" ? list_set(state, path, concat(state[path],[default(parm,1)*state[step]+lastpt])) :
command=="untilx" ? let(
command=="untilx" ? (
let(
int = line_intersection([lastpt,lastpt+state[step]], [[parm,0],[parm,1]]),
xgood = sign(state[step].x) == sign(int.x-lastpt.x)
)
assert(xgood,str("\"untilx\" never reaches desired goal at index ",index))
list_set(state,path,concat(state[path],[int])):
command=="untily" ? let(
list_set(state,path,concat(state[path],[int]))
) :
command=="untily" ? (
let(
int = line_intersection([lastpt,lastpt+state[step]], [[0,parm],[1,parm]]),
ffd=echo(int=int),
ygood = is_def(int) && sign(state[step].y) == sign(int.y-lastpt.y)
)
assert(ygood,str("\"untily\" never reaches desired goal at index ",index))
list_set(state,path,concat(state[path],[int])):
list_set(state,path,concat(state[path],[int]))
) :
command=="xmove" ? list_set(state, path, concat(state[path],[default(parm,1)*norm(state[step])*[1,0]+lastpt])):
command=="ymove" ? list_set(state, path, concat(state[path],[default(parm,1)*norm(state[step])*[0,1]+lastpt])):
command=="jump" ? list_set(state, path, concat(state[path],[parm])):
@ -690,8 +696,9 @@ function turtle_command(command, parm, state, index) =
command=="right" ? list_set(state, step, rot(-default(parm,state[angle]),p=state[step],planar=true)) :
command=="angle" ? list_set(state, angle, parm) :
command=="setdir" ? (
is_vector(parm) ? list_set(state, step, norm(state[step]) * normalize(parm))
: list_set(state, step, norm(state[step]) * [cos(parm),sin(parm)])
is_vector(parm) ?
list_set(state, step, norm(state[step]) * normalize(parm)) :
list_set(state, step, norm(state[step]) * [cos(parm),sin(parm)])
) :
command=="length" ? list_set(state, step, parm*normalize(state[step])) :
command=="scale" ? list_set(state, step, parm*state[step]) :