Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
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

Insectoid

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.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 2 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: