[tw5] TiddlyWiki very handy for generating code in any programming language

Just an example of a macro to generate lines of BASIC code.

Results first, followed by the code.

Results

Code (if viewing in Google Groups, ignore the leading and trailing triple-backticks)

\define AREA(string)

<$let points="$string$"
count={{{ [[$string$]split[ - ]] +[count[]] }}}>

<$list variable="element" filter="[range[1],<count>]">
<$text text={{{ [<element>match[1]then<points>split[ - ]nth[1]addprefix[PSET ]] +[addsuffix[ : AreaStartX = POINT(0) : AreaStartY = POINT(1)]] }}}/>
<$text text={{{ [<element>!match[1]then<points>split[ - ]nth<element>addprefix[LINE - ]] }}}/><br>
</$list>
LINE - (AreaStartX, AreaStartY)

</$let>

\end

<Main 🟠🟠🟠>

`<<AREA "(25,10) - (50,20) - (0,20)">>`
<<AREA "(25,10) - (50,20) - (0,20)">>

`<<AREA "(50,25) - STEP (20,15) - STEP (-10,15) - STEP (-10,-10)">>`
<<AREA "(50,25) - STEP (20,15) - STEP (-10,15) - STEP (-10,-10)">>

1 Like