3 ms·
coincidentally i wrote code to render a hilbert curve in emoji the other day. it was three or four lines of golfed python #!/usr/bin/python3 T=['a'];[T
by kragen 3y ago
coincidentally i wrote code to render a hilbert curve in emoji the other day.
it was three or four lines of golfed python
#!/usr/bin/python3
T=['a'];[T.append(''.join(dict(a='lbffraffarffbl',b='rafflbffblffar').get(c,c)for c in T[-1]))for i in 'abcd'];D,V=[0],1
for c in T[-1]:M,T=dict(f=(1,1),r=(0,1j),l=(0,-1j)).get(c,(0,1));D.append(D[-1]+M*V);V*=T
X=range(31);print('\n'.join(''.join('⬜'[j-i*1j in D]for j in X)for i in X))
hn silently censors that in a way that breaks the code but the original is at http://canonical.org/~kragen/sw/dev3/hilbert.py http://canonical.org/~kragen/sw/dev3/hilbert.py
there is an almost perfectly correct explanation of the code by gpt-4 at https://bin.gy/altypsisca https://bin.gy/altypsisca
the only problem was that gpt-4 guessed wrong about which particular fractal was being drawn
i think the turtle-graphics formulation of the hilbert curve that underlies this l-system is nicer than the manhattan formulation in the linked js. i'm undecided about whether the l-system formulation as string rewrite rules is better or worse than the explicit recursion with conditionals used in the js. fractint's l-system engine includes a `!` operator which swaps left and right, which i think could make the hilbert curve simpler, though the definition in fractint.l doesn't
sudo apt install xfractint and type tlsystem and hit enter to explore more l-systems`
arguably a formulation in terms of a shape grammar or iterated function system would be a better fit
also, if l-systems are the kind of thing you like, you'll probably enjoy http://canonical.org/~kragen/sw/dev3/skitch http://canonical.org/~kragen/sw/dev3/skitch