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
×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 "meroeht" 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

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

Archive

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