FOR [i 1 30] [
REPEAT :i [TYPE "hi]
PRINT []
]
Note: Refer to Chapter 1 (or see Appendix A) to understand the difference between TYPE and PRINT.
ERASE "dcircle
TO dcircle :size ; size is the diameter
REPEAT 360 [FD :SIZE*3.14159/360 RT 1]
END
REPEAT 20 [
dcircle 20+(REPCOUNT*10)
]
This involves drawing squares of increasing size
and turning a few degrees after each square.
HT SETPENSIZE 1 FOR [i 5
105] [
square :i RT 5
]
HT SETPENSIZE 1 REPEAT 100 [
square 5+REPCOUNT
RT 5
]
ERASE "semi.circle
TO semi.circle :size
REPEAT 180 [FD :size/360 RT 1]
END
Continually draw semi-circles each time increasing the size by a little,
and thus get a spiral.
FOR [i 1 25] [
semi.circle 50+:i*20
]
Telescopic arrangement of squares:
This program has two interesting variations: one is obviously the size of
squares, which we know how to implement using counters. The second variation is
in the color of squares. Since we know the color code varies from 1 to 15, we
can once again use a counter to get the series of colors.
ERASE "square TO square :size REPEAT 4 [FD
:size RT 90] END |
ERASE "jump TO jump :x :y PU FD :y RT
90 FD :x LT
90 PD END |
ERASE "pattern
TO pattern :n1 :size
REPEAT :n1 [
BK :size*REPCOUNT/2
square :size*REPCOUNT
FD :size*REPCOUNT/2
jump (:size*REPCOUNT/2)
0
SETPC REPCOUNT
]
END
CS HT SETBG 7 SETPC 0 SETPENSIZE 2
jump -300 0
pattern 8 20
The procedure to draw a filled triangle is quite
straightforward:
ERASE "triangle
TO triangle :size
REPEAT 3 [FD :size RT 120]
END
ERASE "ftriangle
TO ftriangle :size
triangle :size
RT 30 PU FD :size/3 PD FILL BK :size/3 LT 30
END
Next, we should figure out how to get a row of triangles.
Row of 3 triangles, First cut (with plain instructions):
CS
RT 30 ftriangle 100 LT 30
RT 90 FD 100 LT 90
RT 30 ftriangle 100 LT 30
RT 90 FD 100 LT 90
RT 30 ftriangle 100 LT 30
RT 90 FD 100 LT 90
Row of 3 triangles, Second cut (using REPEAT):
CS
REPEAT 3 [
RT 30 ftriangle 100 LT 30
RT 90 FD 100
LT 90
]
Row of triangles, Final cut: (using a procedure)
; Inputs:
; N is the
number of triangles,
; Size is
the size of each triangle
ERASE "hills
TO hills :n :size
REPEAT :n [
RT 30 ftriangle :size LT 30
RT 90 FD :size LT 90
]
END
Now, we can use this procedure to build a pyramid.
Pyramid of base 3, First cut (using plain instructions):
CS
hills 3
100
LT 30 FD 100 LT 60 FD 200 RT 90
hills 2
100
LT 30 FD 100 LT 60 FD 100 RT 90
hills 1
100
LT 30 FD 100 LT 60 FD 0 RT 90
Pyramid of base 3, Second cut (pseudo-procedure with input):
We will use N to indicate the number of hills in the base and S to indicate
the size of each hill. (Note: These are not real Logo instructions yet,
because of N and S)
CS
hills N
S
LT 30 FD
hills
(N-1) S
LT 30 FD
hills
(N-2) S
LT 30 FD
Pyramid, Third cut (using REPEAT and REPCOUNT):
CS
REPEAT N [
hills N-REPCOUNT+1 S
LT 30 FD
]
Now we are ready for conversion to a procedure using N and S as inputs.
The pyramid procedure:
; Inputs:
; N is the
number of triangles in the base,
; Size is
the size of each triangle
ERASE "pyramid
TO pyramid :N :S
REPEAT :N [
hills :N-REPCOUNT+1
:S
LT 30 FD :
]
RT 30 BK :N*:
END
The following program will draw the pyramids.
CS HT SETPENSIZE 2 SETBG 7
jump -350 -100 SETPC 12 pyramid 3 50
jump 200 0 SETPC 13 pyramid 4 50
jump 250 0 SETPC 14 pyramid 5 50
Self-study: Write the same program using the FOR command instead of REPEAT.
This is not really how a peacock feather looks, but we have only tried to
mimic the colors.
This program uses the following procedures:
ERASE "Q.dcircle
TO Q.dcircle :size ; size is the diameter
REPEAT 90 [FD :size*3.14159/360 RT 1]
END
ERASE "petal
TO petal :size ; size is
diameter (of the full circle)
Q.dcircle :size
RT 90
Q.dcircle :size
RT 90
END
A single feather: (we have put a gap by skipping a few petals)
CS SETBG 7
SETPC 13 REPEAT 10 [petal 50 + (5*REPCOUNT)]
SETPC 11 REPEAT 10 [petal 125 + (5*REPCOUNT)]
SETPC 14 REPEAT 10 [petal 165 + (5*REPCOUNT)]
SETPC 6 REPEAT 10 [petal 205 + (5*REPCOUNT)]
SETPC 13 REPEAT 3 [petal 245 + (5*REPCOUNT)]
Flower of feathers:
CS SETBG 7
HT ;hiding
the Turtle makes the drawing faster
REPEAT 5 [
SETPC 13
REPEAT 10 [petal 50 + (5*REPCOUNT)]
SETPC 11
REPEAT 10 [petal 125 + (5*REPCOUNT)]
SETPC 14 REPEAT
10 [petal 165 + (5*REPCOUNT)]
SETPC 6
REPEAT 10 [petal 205 + (5*REPCOUNT)]
SETPC 13
REPEAT 3 [petal 245 + (5*REPCOUNT)]
RT 360/5
]