Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Little Rebol program that demonstrates using 'parse' to interpret some rudimentary Logo commands with a turtle and visual interface
REBOL [
title: "Rudimentary implementation of Logo Turtle"
date: 2015-02-16
author: "Martin Ceronio"
]
{ Load the turtle image; you can find the original at https://edu.kde.org/images/icons/kturtle_32.png Thanks, KTurtle! }
turtle-img: do to-string debase
{bWFrZSBpbWFnZSEgWzMyeDMyICN7CjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMAowMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAKMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwCjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMAowMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAxMDAwNjdBMDcwNjdBMDcwNjdBMDcwNjdBMDcKMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwCjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMAowMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAxMDAwNjdBMDcwNjdBMDcKMDY3QTA3MDY3QTA3MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwCjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMD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DAwMDAwMDAwMEZGCkZGRkZGRkZGRkYwMDAwMDAwMDAwCjAwRkZGRkZGRkZGRkZGRkZGRkZGCkZGRkZGRkZGRkYwMDAwMDAwMDAwCjAwRkZGRkZGCn1d}
{ This represents the "API" of the turtle, including the parse rules for commands issued to it
It also translates commands into drawing commands for VID }
turtle: make object! [
field-size: 400x400
direction: 0
location: field-size / 2
command-history: copy []
draw-commands: copy []
pen-is-down: true
last-error: none
parse-rules: [
some [
['fd | 'forward] set value integer! (move-by value) |
['bk | 'back] set value integer! (move-by value * -1) |
'left set value integer! (turn value * -1) |
'right set value integer! (turn value) |
'color set value word! (set-color value) |
'home (reset) |
['pu | 'penup] (pen-is-down: false) |
['pd | 'pendown] (pen-is-down: true) |
'clear (clear) |
'repeat set value integer! set blk block! (repeat none! value [ parse blk parse-rules ]) |
set word word! (last-error: to-string compose ["unknown word " (word)]) break
]
]
translate-fld: func [location [pair!]] [
location/y: field-size/y - location/y
location
]
turn: func [degrees [integer!]] [
direction: direction + degrees
degrees: degrees // 360
]
set-color: func [color] [
append draw-commands compose [ pen (color) ]
]
reset: func [] [
direction: 0
location: field-size / 2
]
clear: func [] [
reset
pen-is-down: true
draw-commands: copy []
command-history: copy []
]
{ Stores a command and parses it, updating the state and possibly updating draw commands }
command: func [cmd [string!]] [
append/only command-history cmd
process-command cmd
]
{ Moves the turtle in the direction it is currently facing by the distance given; also generates draw commands }
move-by: func [distance [integer!]] [
delta: to-pair compose [(to-integer (sine direction) * distance) (to-integer (cosine direction) * distance)]
if pen-is-down [ append draw-commands compose [line (translate-fld location) (translate-fld location + delta)] ]
location: location + delta
]
process-command: func [cmd [string!]] [
last-error: none
parse to-block cmd parse-rules
]
redraw-commands: func [] [
last-error: none
draw-commands: copy []
reset
for-each cmd command-history [
process-command
if last-error [ break ]
]
]
]
{ User Interface }
view layout [
across
tfield: box white turtle/field-size effect [
draw [ pen red translate 200x200 scale .75 .75 rotate turtle/direction image turtle-img -16x-16 16x16 ]
]
chistory: text-list data turtle/command-history
return
cfield: field [
turtle/command cfield/text
tfield/effect/draw: copy turtle/draw-commands
append tfield/effect/draw compose/deep [ translate (turtle/translate-fld turtle/location) scale .75 .75 rotate (turtle/direction) image turtle-img -16x-16 16x16 ]
if turtle/last-error [ alert turtle/last-error ]
show tfield { Update the drawing area }
show chistory { Update the history text-list }
cfield/text: none
focus cfield
]
do [
focus cfield
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment