- XLogo
This section contains libraries of common procedures which are used throughout the
programs on this site. They are divided into Arcs, Colors, Lists, Maths,
Recursive and Shapes.
In this site, the 'To' and 'End' lines appear with a gray background
to identify the procedure as a common library item.
Some also have a Test procedure to make checking easier.
You can keep these procedures in a special Start Up file. They are automatically loaded and available for use when XLogo starts up. In which case, they are called 'Pseudo Primitives' as they cannot be edited within XLogo.
Download complete library of these procedures.
New
Set defaults for a new drawing. This ensures programs will always work in exactly the
same way. Avoid CS, as it uses screen and pen color preferences that are different for each user.
Used in all programs!
To New
# set default screen, pen and turtle values
ResetAll SetScreenSize [400 400] HideTurtle
SetSC Black SetPC Green SetPS 1 PenUp
End
Arrow
Draw a simple arrow head, usually at the end of a line.
To Arrow :Size
# draw simple end-of-line arrow (tp)
Left 15 Back :Size PenDown
Forward :Size Right 30
Back :Size
PenUp Forward :Size Left 15
End
GridSq
Uses a nested loop to step through successive column by row grid positions. Interchangeable with GridSq below.
Used in Chessboard, Bulge, Fraser, Seaweed and Scintillate.
To GridSq :Order :Side
# draw tile at each column x row position
LocalMake "Offset (1+:Order)/2
For (List "Col 1 :Order) [
For (List "Row 1 :Order) [
SetXY :Side*(:Col-:Offset) :Side*(:Row-:Offset)
Tile :Col :Row :Side] ]
End
GridSq
Draw tiles randomly, by picking a random position from a list of all positions. Interchangeable with GridSq above.
Used in Tile Array and Tile Pattern.
To GridSq :Order :Side
# draw tile at each column x row position
LocalMake "Offset (1+:Order)/2
LocalMake "Ps [] LocalMake "Total :Order*:Order
Repeat :Total [Make "Ps LPut RepCount :Ps]
Repeat :Total [
LocalMake "P Pick :Ps
LocalMake "Ps Remove :P :Ps
LocalMake "Col 1+Mod :P-1 :Order
LocalMake "Row 1+Int (:P-1)/:Order
SetXY :Side*(:Col-:Offset) :Side*(:Row-:Offset)
Tile :Col :Row :Side]
End
Make GridSq relative by changing the last 3 lines to
rSetXY :Side*(:Col-:Offset) :Side*(:Row-:Offset)
Tile :Col :Row :Side
rSetXY Minus :Side*(:Col-:Offset) Minus :Side*(:Row-:Offset) ]
GridRect
Uses a nested loop to step through successive column by row grid positions. Seperate Horizontal and Vertical values of Order are used, allowing a rectangular grid.
Used in ChequerGrid, RGB Swatch
To GridRect :OrderH :OrderV :SqSize
# draw tile at each column x row grid position
LocalMake "OffsetH (1+ :OrderH) /2
LocalMake "OffsetV (1+ :OrderV) /2
LocalMake "SideH :SqSize /:OrderH
LocalMake "SideV :SqSize /:OrderV
For (List "Col 1 :OrderH) [
For (List "Row 1 :OrderV) [
SetXY :SideH*(:Col-:OffsetH) :SideV*(:Row-:OffsetV)
Tile :Col :Row :SideH :SideV] ]
End
Grout
Draw a series of horizontal and vertical lines to form a grid of grout lines between square tiles.
Used in 15
Puzzle.
To Grout :Size :Order
# draw centred square grid with :order divisions
SetPC [64 64 64] SetPW 1
For (List "Point 0 :Size+1 :Size/:Order) [
SetXY :Point-:Size/2 :Size/2 SetH 180
PenDown Forward :Size PenUp
SetXY :Size/2 :Point-:Size/2 SetH 270
PenDown Forward :Size PenUp Wait 2]
End
Jump
Turtles don't normally jump, but if they did, they would jump to a random
position within a square area of side :Side.
Used in DemoStar, Dots, Shapes and WireShapes.
To Jump :Side
# set turtle to random position within square of size side
SetXY (Random :Side) - :Side/2 (Random :Side) - :Side/2
End
rSetXY
Move turtle to new XY position relative to current position. Turtle heading remains unchanged.
To rSetXY :DistX :DistY
# set turtle XY position relative to current position
Right 90 Forward :DistX
Left 90 Forward :DistY
End
Title
Label titles in each corner of the screen. Titles is a list of upto 4 items. An empty list labels nothing.
Used in Ring Wave.
To Title :Titles
# label up to 4 titles
SetPC White Repeat Count :Titles [
Home Right (RepCount*90) -135 Forward 262 SetH 0
If X>0 [SetFontJustify [2 1]] [SetFontJustify [0 1]]
Label Item RepCount :Titles]
End
Ask
Allow the user to select items from a list of possible items. Each item is listed with a numerical key to select.
No selection (just hit return key) selects all items. User can enter item numbers with no spaces (eg 135) if all item numbers less than 9. Selecting items outside the range will return an error.
Returns user selection as a list of items.
Used in Ring Wave.
To Ask :Items
# return list of user selected items
LocalMake "Say List "Select: [_ all]
Repeat Count :Items [
LocalMake "Say LPut List RepCount (Item RepCount :Items) :Say]
Read :Say "Input
If :Input = " [Print "all Output ButFirst ButFirst :Say] # all if no entry
LocalMake "Selection []
ForEach "ItemNo :Input [
LocalMake "Selection LPut (Item :ItemNo+2 :Say) :Selection]
Print :Selection Output :Selection
End
Ask2
Allow the user to select items from a list of possible items. Each item is listed with a numerical key to select.
No selection (just hit return key) selects all items. User can enter item numbers with no spaces (eg 135) if all item numbers less than 9. Selecting items outside the range will return an error.
Returns user selection as a numercal list, with duplicate entries removed.
Used in Platonic Solid.
To Ask2 :Items
# return numerical list of user selected items, duplicates removed
LocalMake "Say [Select: _all] LocalMake "All []
Repeat Count :Items [
LocalMake "Say LPut (Word RepCount "_ Item RepCount :Items) :Say
LocalMake "All LPut RepCount :All]
Read :Say "Input
If :Input = " [Print "all Output :All] # all if no entry
LocalMake "Selection []
ForEach "ItemNo :Input [
If Not Member :ItemNo :Selection [
LocalMake "Selection LPut :ItemNo :Selection] ]
Print :Selection Output :Selection
End