Logo Commands to Draw Circle
If y'all want to work along with this material we suggest using the MSW Logo environment. Information technology is freely available.
Basic Logo Commands
We can employ Logo commands to tell the turtle how to motility.
There are 2 basic turtle movement commands:
- moving the turtle in the direction it is pointing; and
- turning the turtle to point in a new direction.
forward 100 astern 100You tin use whatsoever number of steps you lot like. You lot can also abridge commands, eastward.g.,
forward as fd and astern equally bk. We can tell the turtle to plough. We ask it to turn either right or left and tell it how far to turn in terms of degrees. In that location are 360 degrees in a circumvolve so we tell the turtle to turn between 1 and 360 degrees.
right ninety left ninetyYou can also abbreviate commands, e.1000.,
right every bit rt and left every bit lt. Sometimes we want to get-go over on a clean screen the command for this is.cs (clearscreen)
Endeavour This!
Type in a sequence of commands to describe a foursquare
Sometimes you will give some commands and then find yourself typing them in again and once again. Logo lets you save some typing by repeating a grouping of commands.repeat five [fd seventy rt 72]
You tin can echo any number of times and use whatsoever list of commands inside the [ and ]
Try This!
Can you figure out what the repeat command above will draw?
Blazon it in and run into.
Normally equally the turtle moves it leaves a trail. Y'all can alter the color of the trail, chosen the pen. In Logo there are lots of possible pen colors that the turtle can use. Colors are defined past numbers. black is number 0 and the numbers for more interesting colors are:
- blue
- light-green
- cyan
- blood-red
- magenta
- yellow
- white
- brown
- tan
- forest
- aqua
- salmon
- regal
- orange
- gray
setpencolor command, for example: setpencolor 14
Attempt This!
Type in a setpencolor command and then repeat command above to depict a your favorite colored shape
You can also motion the turtle without it leaving a trail. The penup and pendown commands tell the turtle to enhance and lower the pen respectively. For example, you can draw parallel line segments with this unproblematic sequence of comands:
forward 100 penup correct 90 forward x correct 90 pendown forrad 100
Attempt This!
Use in the penup, pendown, setpencolor and echo commands to draw a dashed green line.
If we've made a prissy picture show nosotros might desire to hide the turtle to get a better view.ht (hideturtle)st (showturtle)
Repeated Patterns
Lots of times our commands are made up of repeating patterns. An AB pattern alternates between two unlike parts. Hither is i in Logo: fd 100 rt 90
Here is an ABC pattern in Logo: fd 100 bk 100 rt 5
Nosotros merely utilise a repeat command to repeat our patterns.
Try This!
Tin can you tell what this control will practise?repeat 4 [fd 100 rt 90]
How well-nigh this one?repeat 72 [fd 100 bk 100 rt 5]
You may desire to refer to the number of times the pattern has been repeated within of the pattern. This can be washed by using the repcount control.
Since Logo is a reckoner programming language information technology has commands to perform mathematical operations:
2 * three = viii - two viii / 2 = 2 + twoY'all can utilise commands in identify of numbers in these mathematical operations.
Attempt This!
Can you tell what this command volition practice?echo 10 [fd repcount * 10 rt xc]
Tin y'all alter information technology then that each "edge" has a dissimilar colour?
Polygons
Try to draw some unproblematic polygons using turtle commands. You can do this by repeating the elementary pattern of "depict border"-"plough right", for example:
trianglesrepeat 3 [fd 100 rt 120]squares
repeat iv [fd 100 rt 90]pentagons
repeat 5 [fd 100 rt 72]
Endeavour This!
How are these different?
How are they the same?
Tin you find a general pattern that each of these is a special instance of?
hint: apply a proper name like "x" in place of a number and try to calculate the other numbers in terms of "x"
Making Your Own Commands
We can brand upwards our own commands. Information technology saves typing and lets united states of america experiment with dissimilar patterns easily.
Instead of typing echo iv [fd 100 rt 90] for a foursquare every time. We tin can ascertain a new command:to square100 repeat 4 [fd 100 rt 90] finish
Now we simply requite the square100 command.
Hither'southward one for general "regular" polygons of dissimilar sizes and colors:
to poly :sides :length :color setpencolor :color repeat :sides [fd :length rt 360/:sides] finish
This control takes numbers every bit an input, much similar the forrad command takes the altitude to move the turtle. In the case of a control that nosotros define, however, we tin decide how to use the input value. These input values are always named with a ":" as their starting grapheme.
At present we can run it as, for example,
poly 4 100 0to describe our black square with sides 100, but nosotros can also run it as:
poly v 70 14to draw an orange pentagon.
Endeavour This!
The file poly.lgo has the poly (and other interesting commands that you lot can explore). Click this link and download the file to your machine (e.thousand., to your desktop).
To load a file, click in the turtle's window, pull down the file menu and select load. You can then select the file you downloaded (eastward.g., to your desktop) to load into the logo environment.
You can make interesting images past rotating geometric objects. Ane simple style is to spin the turtle effectually a point and depict a number of polygons (indicated by the :steps input in the following).
to spin :sides :length :steps repeat :steps [poly :sides :length 0 rt 360/:steps] ceaseEndeavor
spin x thirty xxand
spin 3 80 tenfor a start and experiment with others.
If you want to, endeavor to change the spin command to change the color of the polygon also.
Trees
When you wait at a tree y'all run into a trunk, some branches, and leaves growing of off the branches.
Say you cut off a co-operative and push the cut end into the ground. Does it look like a tree?
What is the aforementioned? What is dissimilar?
Accept a look at these trees and these branches. Notice any patterns?
A fractal is a shape that has a repeating pattern, but where occurrences of the pattern change in location and size (oft times getting smaller). Mathematicians, scientists, and artists are all interested in the study of fractals.
Try This!
Look here for a wide multifariousness of fractals. I peculiarly like the Natural Fractals.
Trees can be thought of as fractals. The thick trunk leads to thinner branches, in plough each branch tin be thought of every bit a trunk leading to thinner branches.
A very simple tree "shape" can be drawn past the post-obit series of Logo commands. Anything written after a ";" is a comment for you to read, only the computer will ignore it so you don't accept to type information technology in.
fd xx ; draw the trunk lt thirty ; draw the left branch fd 14 bk 14 ; support to the branch point rt 60 ; draw the right branch fd 14 bk xiv ; backup to the branch signal lt xxx bk 20 ; back up to the trunk's baseIf y'all type this in it won't await much similar a tree, only this volition serve every bit the basic "fractal" pattern for our trees.
Fractals are programmed in a computer using the idea of recursion. In recursion, we ascertain a command in terms of itself. It seems odd at kickoff, but it is really quite natural. Study this control for drawing a tree trunk and you lot'll see the idea:
to trunk :size if :size < v [end] fd :size lt 30 trunk :size * (7/x) rt 60 trunk :size * (7/10) lt thirty bk :size endIt looks very similar to the command sequence we gave above, except that we use the
torso control itself to draw the left and right branches. We make the branches smaller than the trunk by multiplying their size by vii/10. Each time we phone call trunk nosotros create a smaller branch, until the size of the "torso" is less than five at which point we stop and return to construct the other branches of the tree.
Try This!
The file tree.lgo has lots of interesting tree commands including trunk
Try drawing different tree trunks past giving different inputs.
Trees, and fractals in general, aren't perfectly symmetric like our tree trunks, for instance, some times there is a large co-operative going off the the left and no branch on the correct (it may have been blown off in a storm).
Nosotros can simulate the seemingly random effects of nature on the shape of a tree using Logo'southward random command. random takes a number as input and so randomly selects a number between zero and that number (retrieve of information technology as rolling dice an returning the number showing on the dice).
When you run the random command with the aforementioned number multiple times information technology can produce different numbers (!!). For example,
random 5 = iii random 5 = 2 random 5 = iv random 5 = 3We apply this to vary the size of branches equally follows:
to rantrunk :size if :size < 5 [stop] fd :size lt xxx rantrunk :size * ((5 + (random iv))/x rt 60 rantrunk :size * ((five + (random iv))/10 lt thirty bk :size ceaseThis simple change to the way we reduce the size of the branches has a large effect on the shape of the tree.
Effort This!
Run the rantrunk control several times (clearing the screen) betwixt each run to encounter how the shape changes.
Change sizes some to see how the shape changes.
Now run the command several times without immigration the screen. Come across how the overlapping trees produce a more than complex structure. What happens when you vary the sizes?
These trees are looking better, but nosotros would similar to make them more realistic past adjusting the thickness of the trunk and branches and calculation leaves.
The thickness of the turtle's pen can exist set by the setpensize command. This command takes a list of two numbers that describe the height and width of the pen. For case,
setpensize [3 3]makes the pen 3 times thicker.
We want the trunk to be thicker and the branches to be succesively smaller as we move up the tree.
Attempt This!
Expect at the thicktrunk command to run into how the size is varied. Note that when constructing a list using names rather than numbers, we accept to use (se ...) instead of [...].
How do the thicktrunk trees wait? If yous want to arrange the thickness simply modify the :size/6 to summate a different fraction of :size.
Leaves are fatigued equally an ellipse that is make full with color. They are fatigued at the tips of branches by taking advantage of the fact that our torso's volition cease growing when :size < 5.
Try This!
Draw some different copse using the tree command. You tin can overlap them if you similar and alter their size.
If you want to add some fall foliage, try the falltree command.
Colors
Colors can also be defined by mixing ruddy, dark-green and blue. Imagine you lot have buckets of these paints and you lot pour different amounts into another saucepan then mix them. For instance: yellow is equal parts ruddy and dark-green and no blue. A color mixture is defined by alist of three numbers, each between 0 and 255, describing the corporeality (or intensity) of the reddish, green, and blue you want. Xanthous is [255 255 0]. 1 way to meet the "shading" of a colour is past cartoon concentric circles changine the shade of each a small amount. Here'south an example:
to shadesofyellow echo 255 [ setpencolor (se 255-repcount 255-repcount 0) circle 255-repcount ] stophither we apply
repcount to become the current repetition. In addition we apply the se command to build the color list out of the results of calculations (you can simply employ [...] when yous take simple numbers in the list).
Effort This!
The file colors.lgo has shadesofyellow and a simple rainbow command.
It'due south interesting to meet how changes to the calculations for the different color amounts (i.e., the scarlet, green and blue) changes the resulting color. If you lot want to change the command definition go alee.
Press Your Favorites
If you lot've created an paradigm that you lot really similar, you lot can print it and have it habitation with y'all.Yous might wish to sign it first. The easiest fashion to do this is to type:
penup setxy -200 -200 setpencolor 10 pendown rt 90 label [FirstName LastName]
And then go to the bitmap menu, pull downwardly to print, and select HP Color.
Matthew Dwyer
Source: https://people.cs.ksu.edu/~dwyer/grow/growlogo.html
0 Response to "Logo Commands to Draw Circle"
Post a Comment