Last active
October 22, 2018 08:07
-
-
Save toomasv/dabf9952db7045842a628c93bdf7eec2 to your computer and use it in GitHub Desktop.
Playing with walking turtle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
Date: 2018-10-21 | |
] | |
tick: steps: 0 | |
move: func [dir][ | |
set [rotation step] switch dir [ | |
left [[180 -32x0]] | |
up [[-90 0x-32]] | |
right [[0 32x0]] | |
down [[90 0x32]] | |
] | |
if turn/2 <> rotation [ | |
;print ["turn/2:" turn/2 "rotation:" rotation] | |
rot: switch/default turn/2 [ | |
180 [switch rotation [90 [-90] 0 [-180] -90 [turn/2: -180 90]]] | |
-90 [either rotation = 180 [turn/2: 270 -90][negate -90 - rotation]] | |
90 [rotation - 90] | |
][rotation] | |
] | |
;turn/2: rotation | |
;turtle/offset: turtle/offset + step | |
] | |
view/tight [ | |
size 320x320 | |
on-key [move direction: event/key steps: steps + 1 turtle/rate: 8] | |
turtle: box 32x32 draw [ | |
turn: rotate 0 16x16 [ | |
pen gray | |
line-width 5 | |
line-cap round | |
_head: line 20x15 26x15 | |
_front-right: rotate 0 20x20 [line 20x20 21x24] | |
_front-left: rotate 0 20x10 [line 20x10 21x6] | |
_rear-right: rotate 0 9x20 [line 9x20 8x23] | |
_rear-left: rotate 0 9x10 [line 9x10 8x7] | |
pen off | |
fill-pen brown | |
_shell: rotate 0 16x16 [ellipse 5x7 20x16] | |
] | |
] on-time [ | |
either turn/2 <> rotation [ | |
turn/2: turn/2 + (rot / 9) | |
][ | |
tick: tick + 1 | |
either steps > 0 [ | |
if tick - 1 % 32 + 1 = 32 [steps: steps - 1] | |
case [ | |
any [tick - 1 % 32 + 1 > 25 tick - 1 % 32 + 1 <= 9] [ | |
_front-right/2: _front-right/2 + 6 | |
_rear-right/2: _rear-right/2 - 6 | |
_front-left/2: _front-left/2 + 6 | |
_rear-left/2: _rear-left/2 - 6 | |
] | |
tick - 1 % 32 + 1 > 9 [ | |
_front-right/2: _front-right/2 - 6 | |
_rear-right/2: _rear-right/2 + 6 | |
_front-left/2: _front-left/2 - 6 | |
_rear-left/2: _rear-left/2 + 6 | |
] | |
] | |
face/offset: face/offset + switch direction [ | |
left [-1x0] up [0x-1] right [1x0] down [0x1] | |
] | |
][ | |
face/rate: none | |
tick: 0 | |
] | |
] | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment