Skip to main content
3 of 4
added 87 characters in body
z..
  • 2.1k
  • 1
  • 2
  • 17

Google Sheets, 499 bytes

=SORT(SPARKLINE(LET(F,LAMBDA(F,n,IF(n<3,1,F(F,n-1)+F(F,n-2))),D,LAMBDA(l,o,a,LET(s,SEQUENCE(30*l+1,1,),{s+o*30,SIN(PI()*s/(30*l))*a*l})),W,LAMBDA(W,k,o,a,IF(k<3,D(1,o,a),{W(W,k-1,o,a);W(W,k-2,o+F(F,k-1),-a);D(F(F,k),o,a)})),z,W(W,A1,,1),y,INDEX(z,,1),x,TOCOL(SCAN(,ABS({0;y}-y)>1,LAMBDA(a,c,a+c)),2),IF(A1>2,REDUCE(FILTER(z,x=0),SEQUENCE(COUNTUNIQUE(x)-1),LAMBDA(a,i,LET(k,{a;SORT(a,SEQUENCE(ROWS(a)),)},{QUERY(k,"limit "&XMATCH(VLOOKUP(i,{x,z},2,),INDEX(k,,1),,-1));FILTER(z,x=i)}))),W(W,A1,,1))))) 

enter image description here

As pointed out by @doubleunary in the comments, it turns out that wasn't a bug but just how the function is designed. When drawing across the given coordinates, it never "lifts the pen" so if it draws \$x1 \rightarrow x2 \rightarrow x3\$ and it has to go back to \$x1\$, it draws a line from \$x3 \rightarrow x1\$ ruining the figure. I addressed this issue by filling the gaps with the intermediate coordinates so \$x1 \rightarrow x2 \rightarrow x3 \rightarrow x1\$ becomes \$x1 \rightarrow x2 \rightarrow x3 \rightarrow x2 \rightarrow x1\$ but this doubled the size of the formula and it no longer works beyond order=7, unlike the previous formula that worked up to order=18.

Google Sheets, 250 237 bytes

-13 bytes thanks to @doubleunary

=SORT(SPARKLINE(LET(F,LAMBDA(F,n,IF(n<3,1,F(F,n-1)+F(F,n-2))),D,LAMBDA(l,o,a,LET(s,SEQUENCE(30*l+1,1,),{s+o*30,SIN(PI()*s/(30*l))*a*l})),W,LAMBDA(W,k,o,a,IF(k<3,D(1,o,a),{W(W,k-1,o,a);W(W,k-2,o+F(F,k-1),-a);D(F(F,k),o,a)})),W(W,A1,,1)))) 

It's just an implementation of the code OP provided.

enter image description here

The straight line connecting the start and end of the wave seems to be a bug with the SPARKLINE function.

z..
  • 2.1k
  • 1
  • 2
  • 17