Difference between revisions of "TI-BASIC:Langton Ant"
(Initial automated import) |
(Automated @@ correction) |
||
Line 1: | Line 1: | ||
{{Template:TI-BASIC:Routine | {{Template:TI-BASIC:Routine | ||
− | |picture= | + | |picture= |
|summary=Simulates Langton's ant on the screen. | |summary=Simulates Langton's ant on the screen. | ||
|input=None | |input=None | ||
Line 7: | Line 7: | ||
|compatibility=TI-83/84/+/SE | |compatibility=TI-83/84/+/SE | ||
|author=Arcane Wizard | |author=Arcane Wizard | ||
− | |authors= | + | |authors= |
|url=http://www.unitedti.org/index.php?showtopic=2325&view=findpost&p=43953 United TI | |url=http://www.unitedti.org/index.php?showtopic=2325&view=findpost&p=43953 United TI | ||
|download=[file langtonant.zip] | |download=[file langtonant.zip] |
Latest revision as of 22:11, 24 February 2016
Routine Summary
Simulates Langton's ant on the screen.
Inputs
None
Outputs
None
Variables Used
A, B, C
Calculator Compatibility
TI-83/84/+/SE Author
Arcane WizardURL: United TI Download
:ClrDraw :31→A:47→B :randInt(1,4→C :Repeat getKey :C-1+2pxl-Test(A,B :Ans+4((Ans<1)-(Ans>4→C :Pxl-Change(A,B :B+(Ans=2)-(Ans=4→B :A+(C=3)-(C=1→A :End
[wikipedia:Langton_ant Langton's ant] is a simulation of the movement of an ant, with some simple rules governing it: the ant can move in any of the four cardinal directions, but whenever it goes over one of the previous spots that it was at, it will change direction 90°. Although the ant movement appears chaotic, given enough time it actually ends up being a pattern.
In our routine, the ant is going to be a simple pixel. Before we can display the ant on the screen, however, we need to clear it and initialize its starting position. (47,31) was chosen because it is the exact center of the screen, which should provide the ant with ample room to move around.
We then randomly select a starting direction for the ant to go -- 1 for down, 2 for right, 3 for up, and 4 for left. Once we have a direction selected, we display the ant and it will start moving around. The ant will keep moving around indefinitely until you press a key, although you could limit it to a set number of moves by replacing the Repeat loop with a For( loop.