# Drawing a gnome in Logo

I recently found my first program I wrote using Logo and was wondering if it could have been improved:

to gnome
repeat 180 [bk 1 rt 1] repeat 180 [bk 1 rt 1/4]
rt 97 repeat 180 [bk 1 rt 1/4] pu lt 90 fd 50
lt 90 fd 25
rt 90 pd repeat 90 [fd 1/2 rt 1/4]
repeat 180 [bk 1/2 lt 1/4] pu rt 60 fd 50 pd
repeat 360 [fd 1/4 rt 1] lt 60 pu fd 25 pd
repeat 360 [fd 1/4 rt 1] pu rt 90 fd 50 lt 90 fd 12 rt 180
pd pu bk 20 pd lt 10 repeat 240 [fd 1/2 rt 1/2] pu
fd 50 rt 90 fd 90 rt 180 pd pu lt 30 fd 110 lt 45 fd 10 setfillcolour [0 204 0]
fill pu lt 45 fd 40 setfillcolour [243 143 133] fill
end


I think the only thing I do not remember the reason for is the repeats of pu pd but I think it was to ensure that the pen is up.

Readability would be greatly enhanced by splitting the code into stanzas, using more line breaks, and adding comments.

Why do you like drawing backwards? Going forward is much easier to understand. The first two lines inside the procedure, for example, could be replaced by this code, which draws a counterclockwise path going forward, rather than a clockwise going backward:

to gnome
rt 7
repeat 180 [fd 1 lt 1/4]
lt 97
repeat 180 [fd 1 lt 1/4]
repeat 180 [fd 1 lt 1]

pu lt 83 fd 50
…


There would then be an extra rt 7 command, and it finishes with lt 83 instead of lt 90, but I think that that's a good thing, because it emphasizes that the shape is skewed, not symmetrical.

Some initialization code would be a good idea, to ensure that the turtle is in an expected state. For example, ht pd would hide the turtle and put the pen down. You might also want to set the heading and colour as well.

I don't know what dialect of Logo you are using, but setfillcolour instead of setfillcolor seems unusual.

I think the only thing I do not remember the reason for is the repeats of 'pu pd' but I think it was to ensure that the pen is up.

Indeed, pu is for penup and pd is for pendown. Luckily you remembered what the rest of the instructions do; if you would have used the long versions instead, jumping back into that old code, and just plain reading it, would have been a bit easier.

I can't think of a good reason to use fd over forward and bk over backward, rt over right and lt over left, and so on.

You never call cs/clearscreen, so if you run the script twice in a row, the 2nd run will seem to do nothing, if it doesn't just flicker.

You're also not calling ht to hide the turtle - that's probably slowing down the rendering... although, one of the fun parts of running , is to actually see that turtle running everywhere like crazy.

I wish I had a logo IDE to dig further into the actual code; I'm sure someone else will come along to address that aspect.

• I think I wrote a second program, that cleared the screen, reset the pen colour and hid the turtle, etc. I'm not sure why I used the shorthand version but I do remember drawing the gnome with a lot of trial and error. Perhaps that sped it up that process? – Pureferret Oct 10 '15 at 22:44