Totally Objects Home Page Turtle Graphics Home Page

What's New? Products Totally Objects Downloads Other Downloads Consultancy VAST Training
Educational Discounts See what our clients think Buy News Groups Consultant's Pack Contact Us

Turtle Graphics Example

The following code produced the above:

buildTurtleDemo
| v |
v := VisibilityTurtle newForPrinter: self printer . "Create a new turtle object based on the current Visibility printer"
v      init; "Initialise it"
baseMeasurement: #mm; "Set the measurement scheme to millimeters"
pageSize: 100 @ 100; "Set the page size to 100mm x 100mm"
color: 16; "Set the color to 16 = black in the current palette"
currentBox: v pageSize; "Set the current default box extent to the current page size (100mm x 100mm)"
penDown;  "Set the pen for drawing"
drawOpenBox; "Draw a box of size 100mm x 100mm"
toLeftCenter "Move to the center point of the left hand side (a line is drawn because the pen is down."
toBottomCenter "Move to the center point of the bottom edge"
toRightCenter "Move to the center point of the right hand edge"
toTopCenter "Move to the center point of the top edge - a diamond has been drawn"
toTopLeft; 
toBottomRight; 
toBottomLeft; 
toTopRight;
"Now move to the four points defined - top left hand corner, and so on"
penUp; "Raise the pen - stop drawing"
toCenter; "Move to the center of the page"
penDown; "Lower the pen again"
currentTextJustification: ##c; "Set the text justification to center"
  text:'How to draw lines'. "Draw some text using the current font at the current location using center justification"
^ v "Answer the turtle."

Note that you could have drawn a diamond by using the drawPolygon: anArray method with an array filled with the same locations.

Click here for descriptions of the various commands and settings Click here for a full list of commands and settings

 


Back to Totally Objects Home Page