- HubPages»
- Technology»
- Computers & Software»
- Computer Science & Programming
Coding for Poets - Turtle Graphics
Draw a square
In the beginning, there was a turtle.
I first became acquainted with turtle graphics using Logo. The idea that you could learn coding by drawing shapes quickly caught my interest. Many of the other features of the language, such as lists, also caught my interest. I thought it would be fun to take a look at some code written in Logo and Scratch and see the differences and similarities. For this article, I used Berkeley Logo which you can download free of charge. Click here to play with Logo online without having to download anything.
Let’s begin by drawing a square. Here is the code in Logo.
Logo code that draws a square.
The Logo prompt
The question mark is just the prompt where you type in Logo commands. Here is the square.
The square that the Logo turtle draws
The Logo turtle
The famous Logo turtle is the triangle in the bottom left-hand corner.
Now, let’s see the Scratch code for the square.
Drawing a square using Scratch
The square that Scratch the cat draws
Comparing Logo and Scratch code
So, let’s compare the code. Both example are similar.
Logo has a pendown command just like Scratch. I didn’t use it since Logo’s pen is down my default.
Both use the repeat command to repeat the steps 4 times. Logo uses the forward command to move the turtle while Scratch uses the move command. Logo uses right and the number of degrees to turn, while Scratch uses turn and the number of degrees to turn. Some of the command names may be different but the concept is the same.
So what is different? Two things, how the program is initiated and the interface. A Logo program runs when you press the Enter key. In Scratch, it depends on the event. A Scratch program can start when you click on the green flag, press the space bar, or some other event. This is similar to the way we use technology today. We run apps on our cellphones by pressing the app’s icon.
The interface is also different. With Logo, you type in the commands, with Scratch, you drag and drop. Scratch also lets you use different sprites (cartoon-like characters) to draw or do whatever you want. Logo just has its turtle.
Let’s display some text. The following code displays hello.
Logo code that says "hello"
Writing a sentence
And, this code displays a sentence.
Logo introduces you to Alan
Scratch says "hello"
Here is the Scratch code to display hello.
Scratch "hello" code
Scratch says "hello" output
And, the sentence.
Scratch sentence code
The Scratch cat introduces himself
Glinks Logo Programming
There are some definite differences with the code to display text. With Logo, you use an opening quote to display one word and you use square brackets to display a sentence. Scratch uses the Say command to display a word or sentence.
Scratch is a great language for children and beginners of all ages. The drag and drop interface and colorful blocks make it friendly and inviting.
Logo’s interface may initially appear uninviting. All you see is a question mark. However, once you play with it, you will feel fine.
Have fun and explore both languages.
Here are some sites that provide you a quick overview of Logo.
Basic Logo Commands
Scratch
- Scratch - Imagine, Program, Share
Scratch is a free programming language and online community where you can create your own interactive stories, games, and animations.
Coding stories using Scratch
- Coding stories using Scratch | Alan Cohen | Skillshare
Scratch is a fun and easy-to-use coding language that you access online. This class will teach you coding basics by writing a story. At the end of this class. ..