# Main Command: Go 30 # Single Line CA Ant by Guy Walker # www.logoarts.co.uk to new # set default screen, pen and turtle ResetAll SetScreenSize [400 400] HideTurtle SetSC Black SetPC Green SetPS 1 PenUp end to init Make "Size 2 SetPenWidth :Size end to display :rule :binlist # write header info SetPC White PenUp SetPos [-190 184] Label [1D Cellular Automata] SetPos [70 184] Label List "Rule :Rule SetPos [70 170] Label :BinList end to draw :calist PenDown For (List "N 1 (Count :CAList)) [ SetPC (List 0 (255*Item :N :CAList) 64) Forward :Size] SetPC Black Forward 0 PenUp end to nextline :calist Make "NewCAList [] Make "CAList Sentence :CAList [0 0] #add 0 0 to end Make "LL [0 0 0] For (List "N 1 (Count :CAList)) [ Make "LL ButFirst LPut Item :N :CAList :LL #convert LL into a decimal number Make "X Bin2Dec :LL #convert x to item x of binlist Make "X Item (8-:X) :BinList #add x to newcalist Make "NewCAList LPut :X :NewCAList ] Output :NewCAList end To Dec2Bin :Num # convert decimal number Num to an 8 item binary list If :Num >255 [Print [Rule is too large!] Stop] LocalMake "Bin [] For [C 7 0 -1] [ LocalMake "Bin LPut (Quotient :Num Power 2 :C) :Bin LocalMake "Num :Num -((Power 2 :C) *Last :Bin)] Output :Bin End to bin2dec :binlist # return the decimal value of a 3 bit binary list Output (4*Item 1 :BinList)+(2*Item 2 :BinList)+(Item 3 :BinList) end to go :rule New SetPS 0 Init Make "BinList Dec2Bin :Rule Display :Rule :BinList SetH 90 Make "CAList [1] For (List "N 0 191 :Size) [ SetXY (0-:N) (150-:N) Draw :CAList Make "CAList NextLine :CAList] end