Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off & setlocal enableDelayedExpansion
- call :turtleGraphics
- set "axiom=FX"
- set "var[1]=X"
- set "var[2]=Y"
- set "var[3]="
- set "rule[1]=X+YF+"
- set "rule[2]=-FX-Y"
- set "rule[3]="
- set "angle=90"
- set "generations=8"
- call :build_LSystem
- call :display_LSystem
- pause > nul & exit
- rem The script is controlled entirely from above. All code below are FUNCTIONS to support the LSystem
- rem -------------------------------
- :build_LSystem
- for /l %%a in (0,1,%generations%) do ( set "sentenceLength=0" & set "s=!axiom!#" & set "len=0"
- for %%P in (8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do ( if "!s:~%%P,1!" NEQ "" ( set /a "len+=%%P" & set "s=!s:~%%P!" ) )
- set "sentenceLength=!len!" & set "nextSentence="
- for /l %%i in (0,1,!sentenceLength!) do (
- set "current=!axiom:~%%i,1!"
- if "!current!" equ "%var[1]%" ( set "nextSentence=!nextSentence!%rule[1]%"
- ) else if "!current!" equ "%var[2]%" ( set "nextSentence=!nextSentence!%rule[2]%"
- ) else if "!current!" equ "%var[3]%" ( set "nextSentence=!nextSentence!%rule[3]%"
- ) else ( set "nextSentence=!nextSentence!!current!"
- )
- )
- set "axiom=!nextSentence!" & <nul set /p "=%esc%[2JGenerations %%a/%generations%"
- )
- set "axiom=!axiom:X=!" & set "axiom=!axiom:Y=!" & echo. & set "s=!axiom!#" & set "len=0"
- for %%P in (8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do ( if "!s:~%%P,1!" NEQ "" ( set /a "len+=%%P" & set "s=!s:~%%P!" ) )
- set "sentenceLength=%len%" & echo Sentence Length %sentenceLength%
- goto :eof
- :display_LSystem
- for /l %%i in (0,1,!sentenceLength!) do ( set "current=!axiom:~%%i,1!"
- if "!current!" equ "F" ( %penDown%
- ) else if "!current!" equ "G" ( %penDown%
- ) else if "!current!" equ "-" ( set /a "%turnLeft:?=!angle!%"
- ) else if "!current!" equ "+" ( set /a "%turnRight:?=!angle!%"
- ) else if "!current!" equ "[" ( set /a "%push%"
- ) else if "!current!" equ "]" ( set /a "%pop%"
- )
- <nul set /p "=!turtleGraphics!" & set "turtleGraphics="
- )
- goto :eof
- :turtleGraphics
- rem ////////////////////////////////////////////////////////
- rem The dependancies for the new turtleGraphics, like the old, but shorter names
- set /a "HEI=WID=100"
- set /a "DFX=75","DFY=15","DFA=90"
- mode %wid%,%hei%
- rem OTHER dependancies
- set "_SIN=a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000"
- set "SIN=(a=(x * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832) + (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a) ), %_SIN%) / 10000"
- set "COS=(a=(15708 - x * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832) + (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a) ), %_SIN%) / 10000"
- for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
- rem ALL turtleGraphics functions rewritten as quick macros
- set "forward=DFX+=(?+1)*^!cos:x=DFA^!, DFY+=(?+1)*^!sin:x=DFA^!"
- set "turnLeft=DFA-=(?)"
- set "turnRight=DFA+=(?)"
- set "push=sX=DFX, sY=DFY, sA=DFA"
- set "pop=DFX=sX, DFY=sY, DFA=sA"
- set "draw=?=^!?^!%esc%[^!DFY^!;^!DFX^!HÛ"
- set "home=DFX=0, DFY=0, DFA=0"
- set "cent=DFX=wid/2, DFY=hei/2"
- set "penDown=for %%a in (1 2) do set /a "^!forward:?=1^!" ^& set "^!draw:?=turtleGraphics^!""
- rem \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement