HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Drawing a gnome in Logo

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
logodrawinggnome

Problem

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.

Solution

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
    ; Outline of conehead
    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.

Code Snippets

to gnome
    ; Outline of conehead
    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
    …

Context

StackExchange Code Review Q#107169, answer score: 7

Revisions (0)

No revisions yet.