Help with Logo (Turtle Graphics)
Author |
Message |
ChuChun
|
Posted: Wed Apr 19, 2017 10:40 pm Post subject: Help with Logo (Turtle Graphics) |
|
|
I need to recreate the program Logo in turing, I can't figure out how to get the user's distance input
var direction : int := 0
var x, y : int
var input : string
var i : int := 1
var move : string := "move"
var left : string := "left"
var right : string := "right"
x := 300
y := 200
Draw.Dot (x, y, black)
%Procedure to face left
procedure Left
direction := direction + 90
if direction >= 360 then
direction := 0
end if
end Left
%Procedure to face right
procedure Right
direction := direction - 90
if direction = -90 then
direction := 270
end if
end Right
%Procedure to move forward depending on direction it is facing
procedure Move
var distance : int
if strintok (input(5..*)) then
distance := strint (input(5..*))
end if
if direction = 270 then
Draw.Line (x, y, x + distance, y, black)
elsif direction = 90 then
Draw.Line (x, y, x - distance, y, black)
x := x - distance
elsif direction = 180 then
Draw.Line (x, y, x, y - distance, black)
y := y - distance
else
Draw.Line (x, y, x, y + distance, black)
y := y + distance
end if
end Move
loop
get input : *
if input = move then
Move
elsif input = right then
Right
elsif input = left then
Left
end if
exit when input = "q"
end loop
Help me please. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Fri Apr 28, 2017 2:03 pm Post subject: RE:Help with Logo (Turtle Graphics) |
|
|
distance is an integer. It's as simple as writing 'get distance'. Note that if you input a string, the program will crash. There are ways around this, but we'll cross that bridge when we get there. |
|
|
|
|
![](images/spacer.gif) |
|
|