3D Basics. Basic Exercises.

Working with Basic 3D Graphics.

perspective

Try this piece of code:

cs st repeat 4[repeat 4[fd 50 rt 90] fd 50 down 90]

It should draw 4 squares each on top of the last.

Now type:

perspective

Then try the code again.

To get back to the normal Logo view type:

window

window


normal

perspective


3D view

Basic 3D commands

You should be used to the basic 2D Logo commands: fd bk lt rt.
You should be able to use these to draw a basic polygon.
Try these command line statements.

window
cs st repeat 6[fd 80 rt 60]

The result is a flat hexagon in the plane of the screen.

Now try:

perspective
cs st repeat 6[fd 80 rt 60]

The result is a flat hexagon viewed from a point up and right of the origin.

window


normal

perspective


3D view

Up and Down

These commands tip the turtle upwards or downwards by an angle taken to be in degrees.

perspective
cs down 90 st repeat 6[fd 80 rt 60]

The result is a flat hexagon which looks 'horizontal'.

Now try:

perspective
cs up 60 st repeat 6[fd 80 rt 60]

The result is a flat hexagon tilted towards the viewer.

down


up


rightroll and leftroll

These commands roll the turtle rightwards or leftwards by an angle taken to be in degrees. The turtle is still 'flying' in the same direction but the plane that it will draw in has been tilted.

perspective
cs rightroll 90 st repeat 6[fd 80 rt 60]

The result is a flat hexagon which has been rotated around the 'vertical axis'.

Now try:

perspective
cs leftroll 30 st repeat 6[fd 80 rt 60]

The result is a flat hexagon rotated towards the viewer.

rightroll


leftroll


Visualising up/down

This code will draw a sequence of 'flying squares.' Try to understand exactly what is happening and then modify the code. Try to predict what should happen.

cs repeat 4[repeat 4 [fd 80 rt 90] fd 80 down 30]

You start with a 'vertical' square which gradually flattens out onto a 'horizontal' plane.

Now try:

cs repeat 5[repeat 4 [fd 80 rt 90] fd 80 up repcount*20]

The result is a sequence of squares which 'loop the loop.'

down


up


Visualising leftroll/rightroll

This code will draw a sequence of 'flying squares.' Try to understand exactly what is happening and then modify the code. Try to predict what should happen.

cs repeat 4[repeat 4 [fd 40 rt 90] fd 40 rightroll 30]

You start with a 'vertical' square which gradually rolls rightwards.

Now try:

cs repeat 5[repeat 4 [fd 40 rt 90] fd 40 leftroll repcount*20]

The result is a sequence of squares which roll increasingly leftwards.

rightroll


leftroll


Basic Exercises.

These are a sequence of tasks which draw interesting objects using the commands discussed above.

Prisms

To draw a prism you must first be able to draw a rectangle.

cs repeat 2 [fd 200 rt 90 fd 50 rt 90]

This draws a rectangle

Now try:

perspective

cs repeat 5 [repeat 2 [fd 50 rt 90 fd 200 rt 90] fd 50 up 72]

The result is a sequence of rectangles which fold up into a pentagonal prism.



Cylinders

To draw a cylinder you must first be able to draw a circle.

cs ht repeat 90 [fd 4 rt 4]

This draws a circle which is viewed in perspective mode.

Now try:

cs ht repeat 10 [repeat 90 [fd 4 rt 4] down 90 fd 20 up 90]

The result is a sequence of circles which are moved further away from the viewer on each iteration.



Doughnuts

Instead of pushing the circle away from the viewer you can rotate it instead.

cs ht repeat 100 [repeat 90 [fd 4 rt 4] rightroll 10]


To give the dougnut a wider hole you need to use a procedure.
Start the editor up and paste this code in.

to otorus :rthroat :segsize
repeat 90[
pu home up 30
rightroll repcount*4
rt 90 fd :rthroat lt 90 pd
repeat 180 [fd :segsize rt 2
setpc (list 255-repcount 255-repcount 255-repcount)
fd :segsize rt 4]
]
end

Run the code with the command:

otorus 50 4

Too open the doughnut up you first lift the pen and restore the turtle to the home position.
Then you need to push the turtle out horizontally to the position where you draw the circle.
In order to make the lines easier to see I have also changed their colour using repcount and the setpc command.


Snails

Here is the code for a snail.

to snail :rthroat :segsize :coils
make "segsize0 :segsize
repeat :coils[
make "segsize :segsize0+(:segsize0*repcount/:coils)
pu home up 30
rightroll repcount*4
rt 90 fd :rthroat lt 90 pd
repeat 20 [
setpc (list repcount*12 repcount*12 repcount*12)
fd :segsize rt 18]
]
end

Run the code with the command:

snail 20 8 80


Helix

Here is the code for a helix.

cs ht repeat 500 [fd 5 rt 5 rightroll 1]

I've used the menus on the main window to alter the pensize and colour.


Expanding Helix

Here is the code for a helix that expands.

cs ht up 90 repeat 1000 [fd repcount/50 rt 20 rightroll 2]


Last updated 23rd February 2010