- XLogo library of procedures

This library of procedures draws arcs in various manners. They are used by programs throughout this site including many of the shape procedures. They can be copied and pasted into the Editor window as usual.

I prefer not to use the Arc primitive directly. It is difficult to 'read', uses three arguments, often requires the Minus primitive, and uses absolute headings which are not very logo like. Instead use rArc (relarive Arc).

Download complete library of arc procedures.

rArc

Draw a clockwise arc relative to the turtles heading. The turtle turns
to face the end of the arc. Both **:Angle** and **:Radius** arguments are positive. Putting the angle first makes turtle movements
easier to follow.

Used in many programs instead of primitive Arc.

To rArc :Angle :Radius

# clockwise arc drawn relative to turtle heading

Arc **:**Radius Heading **:**Angle+Heading Right **:**Angle

End

Arch

The Arch procedure draws a symmetrical arch relative to the turtle
heading. The turtle is left unmoved. Both **:Angle** and **:Radius** arguments are positive.

To Arch :Angle :Radius

# symmetrical arc drawn relative to turtle heading

Arc **:**Radius Heading-**:**Angle/2
Heading+**:**Angle/2

End

LeftArc (also see RightArc)

Move turtle along a curved arc to the left. Similar to Left with a radius
of zero. Both **:Angle** and **:Radius** arguments must be positive.

To LeftArc :Angle :Radius

# arc drawn relative to turtle position, angle & radius positive

PenUp Right 90 Back **:**Radius Left **:**Angle

Arc **:**Radius Heading Heading+**:**Angle

Forward **:**Radius Left 90 PenDown

End

RightArc (also see LeftArc)

Move turtle along a curved arc to the right. Similar to Right with a
radius of zero. Both **:Angle** and **:Radius** arguments must be
positive.

To RightArc :Angle :Radius

# arc drawn relative to turtle position, angle & radius
positive

PenUp Left 90 Back **:**Radius

Arc **:**Radius Heading
Heading+**:**Angle

Right **:**Angle Forward **:**Radius Right 90 PenDown

End

'Full' Arc Procedures

The above Arcs are simplified for use as library procedures in programs on this site. Below are more complete Arc procedures which allow for negative angles and angles greater than 360 degrees etc.

rArc

Allow for anti-clockwise arcs if **:Angle** is negative.

To rArc :Angle :Radius

# arc drawn relative to turtle heading

If **:**Angle <0

[Arc **:**Radius **:**Angle+Heading Heading]

[Arc **:**Radius Heading **:**Angle+Heading]

Right **:**Angle

End

Or

To rArc :Angle :Radius

# arc drawn relative to turtle heading

LocalMake "H1 ((Minus **:**Angle) +Abs **:**Angle) /-2

LocalMake "H2 ((Minus **:**Angle) -Abs **:**Angle) /-2

Arc **:**Radius **:**H1 +Heading **:**H2 +Heading

Right **:**Angle

End

Arch

Draw an arch behind the turtle if **:Angle** is negative.

Draw a circle if **:Angle** is greater than 360 degrees.

To Arch :Angle :Radius

# symmetrical arc drawn relative to turtle
heading

If (Absolute **:**Angle)
<360 [

If **:**Angle <0

[Arc **:**Radius 180+Heading+**:**Angle/2 180+Heading-**:**Angle/2]

[Arc **:**Radius Heading-**:**Angle/2 Heading+**:**Angle/2] ]

[Circle **:**Radius]

End

LeftArc (also see RightArc)

StopAll and show error message if **:Radius** is negative as incorrect
arc will be drawn.

If **:Angle** is negative then similar to **RightArc**.

If the pen is up, no curve is drawn.

To LeftArc :Angle :Radius

# arc drawn relative to turtle position

If **:**Radius <0 [Print
[Radius must be positive] StopAll]

If Not PenDown? [Forward **:**Radius Left **:**Angle Forward **:**Radius Stop]

PenUp If **:**Angle <0

[Left 90 Back **:**Radius Arc **:**Radius Heading Heading-**:**Angle

Left **:**Angle Forward **:**Radius Right 90]

[Right 90 Back **:**Radius Left **:**Angle Arc **:**Radius Heading Heading+**:**Angle

Forward **:**Radius Left 90]

PenDown

End

RightArc (also see LeftArc)

StopAll and error message if **:Radius** is negative as incorrect arc
will be drawn.

If **:Angle** is negative then similar to **LeftArc**.

If the pen is up, no curve is drawn.

To RightArc :Angle :Radius

# arc drawn relative to turtle position

If **:**Radius <0 [Print
[Radius must be positive] StopAll]

If Not PenDown? [Forward **:**Radius Right **:**Angle Forward **:**Radius Stop]

PenUp If **:**Angle <0

[Right 90 Back **:**Radius Right **:**Angle Arc **:**Radius Heading Heading-**:**Angle

Forward **:**Radius Left 90]

[Left 90 Back **:**Radius Arc **:**Radius Heading Heading+**:**Angle

Right **:**Angle Forward **:**Radius Right 90]

PenDown

End

Curve

Arcs (and circles) cannot be filled using the FillPolygon primitive. They have to be drawn as a series of small steps. Here is a possible procedure to do this.

To Curve :Angle :Radius

# curved arc drawn relative to turtle position

LocalMake "myHeading Heading

LocalMake "Steps 12+Integer Absolute **:**Radius

LocalMake "StepSize ((2*Pi***:**Radius)
*(**:**Angle/360)) /**:**Steps

LocalMake "StepAngle **:**Angle/**:**Steps

Forward :StepSize/2

Repeat **:**Steps-1 [Right **:**StepAngle Forward **:**StepSize]

Right **:**StepAngle Forward **:**StepSize/2

SetH **:**myHeading+**:**Angle

End