Langton's ant: Difference between revisions
Content added Content deleted
m (→{{header|jq}}: ANSI code) |
|||
Line 3,861: | Line 3,861: | ||
{ „direction” } |
{ „direction” } |
||
</syntaxhighlight> |
|||
=={{header|Peri}}== |
|||
<syntaxhighlight lang="peri"> |
|||
###sysinclude standard.uh |
|||
###sysinclude system.uh |
|||
###sysinclude str.uh |
|||
###sysinclude X.uh |
|||
#g |
|||
$ff0000 sto szin1 |
|||
$ffffff sto szin2 |
|||
10 sto pausetime |
|||
//maxypixel 100 - sto YRES |
|||
//maxypixel 20 - sto YRES |
|||
//maxypixel 7 - sto YRES |
|||
//maxypixel 13 - sto YRES |
|||
maxypixel 20 - sto YRES |
|||
maxxpixel sto XRES |
|||
zero ant |
|||
// Az ant iránykódjai: |
|||
// 0 : fel |
|||
// 1 : le |
|||
// 2 : jobbra |
|||
// 3 : balra |
|||
@XRES 2 / sto antx // Az ant kezdeti koordinátái |
|||
@YRES 2 / sto anty |
|||
myscreen "Furor monitor" @YRES @XRES graphic // Create the graphic screen |
|||
."Kilépés: ESC\n" |
|||
{.. // infinite loop begins |
|||
myscreen @anty @antx getpixel // A pixel színe amin az ant ül épp |
|||
@szin2 == { |
|||
myscreen @anty @antx @szin1 setpixel // másik színre átállítjuk a pixelt |
|||
2 // Jobbra fog fordulni |
|||
}{ |
|||
myscreen @anty @antx @szin2 setpixel // másik színre átállítjuk a pixelt |
|||
3 // Balra fog fordulni |
|||
} |
|||
// Elvégezzük az új koordináta beállítását: |
|||
sto direction |
|||
@ant 0 == @direction 2 == & { ++() antx @antx @XRES == { zero antx } 2 sto ant goto §beolvas } |
|||
@ant 0 == @direction 3 == & { @antx inv { @XRES -- sto antx }{ --() antx } 3 sto ant goto §beolvas } |
|||
@ant 1 == @direction 3 == & { ++() antx @antx @XRES == { zero antx } 2 sto ant goto §beolvas } |
|||
@ant 1 == @direction 2 == & { @antx inv { @XRES -- sto antx }{ --() antx } 3 sto ant goto §beolvas } |
|||
@ant 2 == @direction 2 == & { @anty inv { @YRES -- sto anty }{ --() anty } 1 sto ant goto §beolvas } |
|||
@ant 2 == @direction 3 == & { ++() anty @anty @YRES == { zero anty } 0 sto ant goto §beolvas } |
|||
@ant 3 == @direction 2 == & { ++() anty @anty @YRES == { zero anty } 0 sto ant goto §beolvas } |
|||
@ant 3 == @direction 3 == & { @anty inv { @YRES -- sto anty }{ --() anty } 1 sto ant goto §beolvas } |
|||
beolvas: |
|||
myscreen key !sto billkód @pausetime inv sleep $1b == { |
|||
."Made " {..} print ." generations.\n" {.>.} } |
|||
..} |
|||
myscreen inv graphic |
|||
end |
|||
{ „myscreen” } |
|||
{ „billkód” } |
|||
{ „pausetime” } |
|||
{ „XRES” } |
|||
{ „YRES” } |
|||
{ „szin1” } |
|||
{ „szin2” } |
|||
{ „ant” } |
|||
{ „antx” } |
|||
{ „anty” } |
|||
{ „direction” } |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||