mscroggs.co.uk
mscroggs.co.uk

subscribe

Blog

Logo Asteroids

 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
×2      ×1                  ×2
(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
×1                 Reply
Bravo! Can't wait to try this!
Bolti
×1                 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
            ×1     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 "elbatnuocnu" backwards 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

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

Archive

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