Dr Logo for the Tatung Einstein, showing a rosette drawn by the turtle
← Back to Courses
module
23

Curves

Introduction

Dr Logo has no primitive that draws a circle. It does not need one.

Go forward a little, turn a little, and do it enough times, and you are back where you started having drawn something no one would call a polygon.

A circle

repeat 36 [fd 5 rt 10]

Thirty-six turns of ten degrees is one full revolution. Each side is five steps long, so the turtle walks 180 steps in all - and a loop 180 round has a diameter of about 57, which is what you get.

a circle made of thirty-six straight lines

Two numbers control it and they do different jobs:

  • The step sets the size. Thirty-six steps of 10 give a circle 57 across; thirty-six steps of 15 give one nearly three times that, which is too big for the screen.
  • How many, and how far each turn must multiply to 360, or you get an arc instead of a circle. That is not a fault. That is the next idea.

Why not repeat 360 [fd 1 rt 1]?

Because you will be waiting. Dr Logo draws about eleven turtle steps a second, so a 360-sided circle takes the best part of half a minute, and on a 256-pixel screen it looks exactly like the 36-sided one that took three seconds.

Ten degrees a step is smooth enough for anything the Einstein can display. Save the fine steps for when you can see the difference.

An arc is a circle you stopped early

arc 5 36 is the whole circle. arc 5 9 is a quarter of it - nine steps of ten degrees is ninety. arc 5 18 is a half.

A flower

Two quarter arcs with a right angle between them make a petal:

Walk it through. Curve round ninety degrees, turn sharply, curve back ninety, turn sharply again - and you are where you began, facing how you began. That is the same closing trick as S22's bar, and it buys the same thing:

repeat 6 [petal 5 rt 60]

The code

Starting from

A fresh boot, at the ? prompt.

What you should see

six petals meeting at a centre

It takes about ten seconds. Six petals, because six sixties are 360.

The other kind of curve

A circle comes from turning. A wave comes from working out where each point should be and going there - and for that Dr Logo has sin.

?show sin 30
0.5
?show sin 90
1

Degrees, not radians, and the answer is a decimal between -1 and 1. Multiply it by how tall you want the wave, and you have a height for every angle:

se builds the [x y] pair that setpos wants out of the two numbers. Run it from the left-hand edge with the pen already down at the first point:

cs ht pu setpos [-120 0] pd
wave 0

two cycles of a sine wave

Two full cycles, because 720 degrees is twice round.

Change one thing

  • arc 15 36. The circle is bigger than the screen. What happens at the edge, and does Dr Logo tell you?
  • Change rt 60 to rt 45 in the flower line and repeat 6 to repeat 8. Then try eight petals with rt 60 still in place and see what a mismatch looks like.
  • setscrunch 2, then draw the circle again. The width is untouched and the height doubles - setscrunch stretches the picture vertically, and 1 is what you start with.
  • Change sin to cos in wave. The curve starts at the top instead of the middle - and you get an unwanted vertical line at the left. Work out where it came from.

When it goes wrong

Symptom Cause
A polygon, not a circle The step is too long for the turn. Smaller fd, or more steps.
It never closes The steps and the turn do not multiply to 360.
It is taking forever Too many steps. repeat 36 [fd 5 rt 10] looks the same as repeat 360 [fd 1 rt 1] and is ten times faster.
Part of the circle is missing It is bigger than the screen. Lines outside are not drawn and you are not told.
The circle is an oval setscrunch is not 1. show sf reports it as the last of the five things it gives you.
A stray line at the start of a plotted curve The pen was down somewhere else when the first setpos ran.

Summary

A circle is repeat 36 [fd n rt 10] - thirty-six straight lines, with the step setting the size and the numbers multiplying to 360. Stop early and you have an arc; make a shape that closes and you can repeat it into a flower. For a curve that is not made of turning, sin gives a height for an angle in degrees and setpos puts the turtle there.

Next

S24, patterns - what happens when you repeat something that very nearly closes.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.