mscroggs.co.uk
mscroggs.co.uk

subscribe

Blog

 2023-04-12 
If, like me, you grew up in the 90s, then one of your earliest experiences of programming was probably using Logo. In Logo, you use various commands to move a "turtle" around the screen. As the turtle moves, it can draw lines. I have a very strong memory from early secondary school of spending a few maths lessons in the computer room writing Logo programs to draw isometric houses.
If you read this blog regularly, you'll probably have noticed that I'm a fan of the game Asteroids. Over the last few weeks, I've been working on Logo Asteroids, a version of Asteroids where you control your spaceship using Logo commands. You can play this game at mscroggs.co.uk/logo.
If you've not used Logo before, or if it's been so long since you have that you've forgotten the commands, this blog post will guide you through how to get started. If you're confident in your Logo skills, you might still want to scroll to the end of this post, where I share some custom Logo commands that you might find helpful.
The game's source code is available on Github; you can also use the GitHub issue tracker to report bugs and make feature requests.

Moving the turtle

If you're starting out in Logo, the first thing you'll want to do is move the turtle. You can move it forwards or backwards using the commands fd or bk followed by a number of pixels:
 Logo 
fd 100
bk 75
To change the direction in which the turtle is facing, you can use the command rt (right) or lt (left) followed by an angle in degrees:
 Logo 
rt 90
lt 45
You can also chain together multiple commands on a single line like this:
 Logo 
fd 100 rt 90 fd 100 lt 90
By default, a line is drawn whenever the turtle moves forward or backwards. You can stop lines from being drawn by running the command pu (pen up). To start drawing again, run pd (pen down). If you want to make the game needlessly harder for yourself, you can use the command ht (hide turtle). To make the game easier again, run st (show turtle).
In a normal Logo program, the lines that you draw will stay there until you clear the screen (cs). In Logo Asteroids, the lines will only be visible for a limited amount of time, and the asteroids will bounce off them while they are visible. To prevent too many lines from being drawn too quickly, the turtle can move a maximum of 1000 pixels in a single command (or chain of commands).

Special commands for Logo Asteroids

As well as the Logo commands, there are some commands I have included that are specific to Logo Asteroids. These are:
 Logo 
start
fire
help
The command start will start the game. You'll need to run this before you can run any other commands. You'll also need to run it to start the game again if you run out of lives.
The command fire will fire at the asteroids. This command can be run a maximum of 10 times by a single chain of commands.
The command help will show details of all the available commands below the game.

Defining your own subroutines

If you write some Logo commands that you want to use lots of times, use can use the to command to define a subroutine. For example, the following code defined a command called square that will draw a square of side length 50.
 Logo 
to square fd 50 rt 90 fd 50 rt 90 fd 50 rt 90 fd 50 rt 90 end
The subroutine can then be used by running:
 Logo 
square
The square subroutine can be simplified by using the repeat command:
 Logo 
to square repeat 4 [fd 50 rt 90] end
... or it could be made to take a side length as input:
 Logo 
to square :side repeat 4 [fd :side rt 90] end
This updated version of the square subroutine can then be used by running:
 Logo 
square 50
square 100
square 125

Helpful subroutines for Logo Asteroids

To help you get going with Logo Asteroids, I've written a few subroutines that you might find helful. See if you can work out what they do before running them.
 Logo 
to burst repeat 10 [fire rt 36] end
to protect pu fd 30 pd rt 135 repeat 4 [fd 30 * sqrt 2 rt 90] lt 135 pu bk 30 pd end
to multifire rt 10 repeat 10 [fire lt 2] rt 10 end
If you write your own helpful subroutine, share it in the comments below. You can put <logo> and </logo> HTML tags around your subroutine to make it display more nicely in your comment.
To end this blog post, here's one final subroutine for you to try out:
 Logo 
to house pu setxy 400 225 seth 0 pd lt 30 fd 40 lt 60 fd 40 lt 120 fd 40 lt 60 fd 40 rt 120 fd 50 rt 60 fd 40 rt 120 fd 50 setxy 400 + 20 * cos 30 155 rt 180 fd 50 setxy 400 - 50 * cos 30 160 pu setxy 400 + 20 * cos 30 155 pd setxy 400 + 40 * cos 30 165 pu setxy 400 225 lt 60 pd fd 50 rt 60 fd 50 rt 120 fd 50 pu rt 60 fd 20 pd lt 120 fd 20 rt 120 fd 10 rt 60 fd 20 rt 60 fd 50 pu rt 60 fd 10 pd rt 120 fd 50 ht end
×5      ×5      ×3      ×3      ×5
(Click on one of these icons to react to this blog post)

You might also enjoy...

Comments

Comments in green were written by me. Comments in blue were not written by me.
Very cool! Here's a combination of your "burst" and "protect" subroutines:

to f pu sety 195 setx 390 pd repeat 10 [fire fd 20 rt 36] pu home end
Aaron
×3   ×3   ×4   ×4   ×4     Reply
Bravo! Can't wait to try this!
Bolti
×6   ×2   ×2   ×2        Reply
I didn't include this one in the blog post, but here's a bonus fun command:
to randwalk repeat 100 [rt random 360 fd 10] end


Matthew
×4   ×4   ×4   ×4   ×5     Reply
 Add a Comment 


I will only use your email address to reply to your comment (if a reply is needed).

Allowed HTML tags: <br> <a> <small> <b> <i> <s> <sup> <sub> <u> <spoiler> <ul> <ol> <li> <logo>
To prove you are not a spam bot, please type "d" then "e" then "c" then "a" then "g" then "o" then "n" in the box below (case sensitive):

Archive

Show me a random blog post
 2024 

Feb 2024

Zines, pt. 2

Jan 2024

Christmas (2023) is over
 2023 
▼ show ▼
 2022 
▼ show ▼
 2021 
▼ show ▼
 2020 
▼ show ▼
 2019 
▼ show ▼
 2018 
▼ show ▼
 2017 
▼ show ▼
 2016 
▼ show ▼
 2015 
▼ show ▼
 2014 
▼ show ▼
 2013 
▼ show ▼
 2012 
▼ show ▼

Tags

go polynomials tmip raspberry pi error bars folding tube maps fractals bempp latex squares logo cross stitch mathsteroids chebyshev golden spiral the aperiodical folding paper stickers wool determinants correlation fence posts palindromes data visualisation geogebra python matrices matrix multiplication pizza cutting guest posts statistics wave scattering final fantasy turtles datasaurus dozen a gamut of games errors world cup mean bodmas finite element method quadrilaterals propositional calculus logs newcastle matrix of minors chess big internet math-off rhombicuboctahedron logic royal institution preconditioning numbers runge's phenomenon matrix of cofactors inline code royal baby dragon curves mathsjam sorting european cup anscombe's quartet simultaneous equations signorini conditions dinosaurs computational complexity zines estimation map projections youtube edinburgh plastic ratio draughts realhats data dates triangles misleading statistics tennis 24 hour maths arithmetic standard deviation binary oeis christmas card chalkdust magazine bubble bobble exponential growth video games graphs stirling numbers game of life martin gardner weak imposition hannah fry rugby ternary geometry sound crochet craft radio 4 noughts and crosses golden ratio gaussian elimination weather station light curvature phd sport hexapawn frobel cambridge menace programming trigonometry convergence manchester science festival pi approximation day inverse matrices live stream accuracy braiding interpolation hats platonic solids london talking maths in public matt parker databet asteroids ucl books fonts people maths boundary element methods numerical analysis hyperbolic surfaces approximation sobolev spaces news graph theory national lottery pac-man flexagons electromagnetic field puzzles countdown javascript advent calendar games captain scarlet christmas pi manchester crossnumber gather town php pythagoras reddit dataset coins london underground reuleaux polygons football machine learning mathslogicbot recursion nine men's morris finite group game show probability probability harriss spiral speed gerry anderson pascal's triangle

Archive

Show me a random blog post
▼ show ▼
© Matthew Scroggs 2012–2024