# Building_Blocks_2

The intent is to:

- Show the turtle at any moment to engage the concept for kids (SHOWTURTLE)
- Show the procedures running in the Listener window while showing the turtle in the Graphics window at the same time using the TRACE command.
- Demonstrate that with 3 basic procedures: ELEMENT, ROTATE_ELEMENT, and GRAPH_SIN, you can build al lot of new and more complex graphs.
- Show the use of some of the powerful commands like: SETWIDTH, SETPC, TURTLETEXT, SETSPEED, DOT, etc. particularly to show the different speeds, colors, widths and the powerful results for designing and drawing at high speed.

I wanted to catch the attention of:

- kids at Elementary (with the Turtle and colors),
- kids at Middle School (with the rotations),
- kids at Highschool with the sin(x) in the x-axis and y-axis.
- teachers who are willing to have a tool to teach coding for all levels.

Notes to the version 2 of Building Blocks:

- Using PPROP “ICONBAR “STATE “HIDDEN and SETXY (which is more powerful than I thought) I created a second version of the Building Blocks program.
- I have improved the speed (to show the power of the SETSPEED command), but more importantly, I am making visible how the procedures run, which is the objective of this program (for teaching purposes).

#### Building_Blocks_2.lgo

```
;Building Blocks: POLYGONS, ROTATION and SIN(X)
;Similar to Building Blocks 1 with improved features
;by Luis Noriega
TO VERTICAL_LAYOUT
MAKE "LAYOUT [
GRAPHICS [[0 0 69 100] NORMAL]
LISTENER [[69 0 31 100] NORMAL]
TOOLBOX [[80 0 20 25] HIDDEN]
FILES [[5 10 20 25] HIDDEN]
HELP [[25 20 30 50] HIDDEN]
EDITOR [[10 10 50 50] HIDDEN]
BLOCKS [[0 0 50 70] HIDDEN]
ICONBAR [[0 0 0 0] NORMAL]
]
END
TO PREPARE
PPROP "ICONBAR "STATE "HIDDEN
CLEARTEXT
CLEARSCREEN
HT
CS
SETPC 0
HOME
ST
END
TO INITIALPOSITION
SETPC 0
ST
PU
SETXY [-360 0] SETHEADING 270
;HOME
;LT 90
;FD 360
RT 90
END
TO ELEMENT :SIDES :SIZE :SPEED :COL :ANCHO :LLENA :SHOW :SEE
PD
SETPC :COL
SETSPEED :SPEED
SETWIDTH :ANCHO
SETFONT “TIMES 18 1
IF :SHOW = 1 THEN RUN [RT 90 TT (WORD "| | "Element "| (| :SIDES "|, , , )|) LT 90]
REPEAT :SIDES [
FD :SIZE
RT 360 / :SIDES
IF :SEE=1 WAIT 600/:SIDES
]
IF :LLENA =1 THEN FILL_COLOR :SIZE :ANCHO
PU
SETWIDTH 1
SETPC 0
END
TO FILL_COLOR :SIZE :ANCHO
SETSPEED .5
PU
FD 20
RT 90
FD :ANCHO + 5
PD
WAIT 500
FILL
PU
BK :ANCHO + 5
LT 90
BK 20
END
TO ROTATE_ELEMENT :SIDES :TIMES :COL :SIZE :SPEED :SHOW :SHOWROTATION :SEE
SETPC :COL
PD
IF :SHOWROTATION = 1 THEN TT (WORD "| | "Rotating "| (| :TIMES "|Times (Element (| "| | :SIDES "|, , , )) |)
REPEAT :TIMES [
ELEMENT :SIDES :SIZE :SPEED :COL 2 0 :SHOW :SEE
RT 360 / :TIMES
]
SETPC 0
END
TO GRAPH_SIN :DEGREES :JUMP
PRINT "|Preparing to draw Sin(x)|
PU
MAKE "HORIZONTALMOVE 1
XY_AXIS
PRINT "|Entering GRAPH _SIN :DEGREES :JUMP|
PU
SETXY [-300 200]
SETFONT “TIMES 25 3
PD
TT "|Sin(x)|
WAIT 1000
INITIALPOSITION
SETFONT "TIMES 14 1
PD
SETWIDTH 2
SETSPEED 1
REPEAT :DEGREES [
INITIALPOSITION
RT 90
FD :HORIZONTALMOVE
LT 90
FD 15
PD
;ORIGINAL SET OF COMMANDS TO DRAW THE DEGREES IN THE X AXIS:
;IF :HORIZONTALMOVE = 83 THEN TT "90
;IF :HORIZONTALMOVE = 173 THEN TT "180
;IF :HORIZONTALMOVE = 263 THEN TT "270
;IF :HORIZONTALMOVE = 353 THEN TT "360
;IF :HORIZONTALMOVE = 443 THEN TT "450
;IF :HORIZONTALMOVE = 533 THEN TT "540
;IF :HORIZONTALMOVE = 623 THEN TT "630
;IF :HORIZONTALMOVE = 713 THEN TT "720
;NEW SET OF COMMANDS THANKS TO MICHAEL DAUMLING SUGGESTION
LMAKE "DEGREES :HORIZONTALMOVE + 7
IF (REMAINDER :DEGREES 90) = 0 THEN TT :DEGREES
;OTHER WAY TO DO THE SAME IS USING THE CASE COMMANDD
;CASE :HORIZONTALMOVE [
; [83 [TT "90]]
; [173 [TT "180]]
; [263 [TT "270]]
; [353 [TT "360]]
; [443 [TT "450]]
; [533 [TT "540]]
; [623 [TT "630]]
; [713 [TT "720]]
;]
PU
BK 15
MAKE "VERTICALMOVE PRODUCT 80 SIN :HORIZONTALMOVE
ST
FD :VERTICALMOVE
PD
WAIT 1
;PRINT :HORIZONTALMOVE + 1
(DOT)
MAKE "HORIZONTALMOVE SUM :HORIZONTALMOVE :JUMP
PD
PU
]
SETSPEED 0.9
INITIALPOSITION
END
TO XY_AXIS
SETSPEED .9
INITIALPOSITION
SETWIDTH 1
PD
RT 90
FD PRODUCT 370 2
SETFONT “TIMES 14 1
LT 90
PU
FD 15
PD
TT “|x (Degrees)|
PU
BK 15
RT 90
BK PRODUCT 370 2
LT 90
PD
FD 88
TT "-1
FD 82
TT "| y|
PD
BK 170
END
TO MOVE_GRAPH_SIN :DEGREES :JUMP
PU
SETSPEED 0.9
SETXY [-180 330]
SETFONT “TIMES 25 3
PD
TT "|Red&Blues along Sin(x) at high speed:|
WAIT 1000
INITIALPOSITION
MAKE "HORIZONTALMOVE 1
SETSPEED 1
PRINT "|At high speed!|
PD
REPEAT :DEGREES [
INITIALPOSITION
RT 90
FD :HORIZONTALMOVE
LT 90
MAKE "VERTICALMOVE PRODUCT 80 SIN :HORIZONTALMOVE
ST
FD :VERTICALMOVE
MAKE "HORIZONTALMOVE SUM :HORIZONTALMOVE :JUMP
PD
BLUE&RED 1 0 0
PU
]
END
TO BLUE&RED :SPEED :SHOWROTATION :SEE
SETFONT “TIMES 14 1
REPEAT 1 [
;PRINT "BLUE
ROTATE_ELEMENT 10 10 "BLUE 25 :SPEED 0 :SHOWROTATION :SEE
;PRINT "RED
RT 90
ROTATE_ELEMENT 10 10 "RED 25 :SPEED 0 :SHOWROTATION :SEE
LT 90
]
END
TO TRACING
TRACE [
ELEMENT
X&Y_AXIS
ROTATE_ELEMENT
BLUE&RED_ELEMENTS
FILL_COLOR
]
END
TO UNTRACING
UNTRACE TRACED
END
;Main program
TO MAIN
VERTICAL_LAYOUT
PREPARE
TRACING
PRINT "|Running MAIN!|
PU
SETSPEED 0.9
SETXY [-300 -260]
SETFONT “TIMES 30 1
PD
TT "|Combining 3 procedures: Element, Rotate, and Sin(x)|
WAIT 1000
PU
SETXY [-250 -300]
SETFONT “TIMES 20 1
PD
TT "|We want to see the Turtle and the Listener panel while running.|
WAIT 1000
SETSPEED .9
PU
HOME
ST
PU
SETSPEED 0.5
HOME
FD 40
LT 90
ELEMENT 3 160 1 "BLACK 3 1 1 1
SETSPEED .9
RT 90 FD 80 RT 90 FD 200 LT 180
ELEMENT 4 150 1 "RED 12 1 1 1
SETSPEED .9
BK 150 LT 90 FD 340 RT 90
ELEMENT 5 180 1 "ORANGE 30 1 1 1
SETSPEED .9
FD 550 RT 90 FD 55 LT 90 RT 90
ROTATE_ELEMENT 3 12 "GREEN 80 1 0 1 1
ST
PU
GRAPH_SIN 360 2
PU
SETSPEED 0.5
SETXY [-500 140]
SETFONT “TIMES 25 3
PD
TT "|Blue&Red:|
WAIT 1000
PD
INITIALPOSITION
ST
SETSPEED 0.5
INITIALPOSITION
BLUE&RED 1 1 1
ST
UNTRACING
PRINT "|Entering MOVE_GRAPH_SIN|
MOVE_GRAPH_SIN 720 1
SETPC 0
PRINT "|End of main program|
PRINT "|Use may use Windows/Select Layout|
PRINT "| or Windows/Restore Layout|
PRINT "|to see and edit the program.|
END
MAIN
```

- Procedure: ELEMENT, ROTATE_ELEMENT, and GRAPH_SIN
- Description: A set of procedures for building blocks with Polygons, Rotations, and Sin(x)
- Level: Beginner, intermediate and advanced
- Tags: Color, Fill, Set Width, Pen Color, Turtle Text, Set Speed, Drawing, Dot, PPROP, SETXY