Terrapin Resources

# Building_Blocks_1

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.

#### Building_Blocks_1.lgo

``````;Building Blocks: POLYGONS, ROTATION and SIN(X)
;by Luis Noriega

MAKE "LAYOUT [
GRAPHICS [[0 0 75 100] NORMAL]
LISTENER [[75 0 25 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]
]

TO PREPARE
CLEARTEXT
CLEARSCREEN
HT
CS
SETPC 0
HOME
ST
END

TO INITIALPOSITION
SETPC 0
ST
PU
HOME
LT 90
FD 360
RT 90
END

TO ELEMENT :SIDES :SIZE :SPEED :COL :ANCHO :LLENA
PD
SETPC :COL
SETSPEED :SPEED
SETWIDTH :ANCHO
REPEAT :SIDES [
FD :SIZE
RT 360 / :SIDES
]
IF :LLENA =1 THEN FILL_COLOR :ANCHO
PU
SETWIDTH 1
SETPC 0
END

TO FILL_COLOR :ANCHO
PU
FD :ANCHO + 5
RT 90
FD :ANCHO + 5
PD
FILL
BK :ANCHO + 5
LT 90
BK :ANCHO + 5
END

TO ROTATE_ELEMENT :SIDES :TIMES :COL :SIZE :SPEED
SETPC :COL
PD
REPEAT :TIMES [
ELEMENT :SIDES :SIZE :SPEED :COL 2 0
RT 360 / :TIMES
]
SETPC 0
END

TO GRAPH_SIN :DEGREES :JUMP :GROSOR
PRINT "This.is.SIN.X
PU
MAKE "HORIZONTALMOVE 1
X&Y_AXIS
SETSPEED 1
SETWIDTH :GROSOR
PRINT "Printing.Degrees:
REPEAT :DEGREES [
INITIALPOSITION
RT 90
FD :HORIZONTALMOVE
LT 90
MAKE "VERTICALMOVE PRODUCT 80 SIN :HORIZONTALMOVE
ST
FD :VERTICALMOVE
PD
PRINT :HORIZONTALMOVE + 1
(DOT)
MAKE "HORIZONTALMOVE SUM :HORIZONTALMOVE :JUMP
PD
PU
]
SETWIDTH 1
END

TO X&Y_AXIS
SETSPEED .9
INITIALPOSITION
SETWIDTH 1
PD
RT 90
FD PRODUCT 365 2
SETFONT “TIMES 14 1
LT 90
PU
FD 15
PD
TT “X
PU
BK 15
RT 90
BK PRODUCT 365 2
LT 90
PD
FD PRODUCT 85 2
TT "Y
PD
BK PRODUCT 85 2
END

TO MOVE_GRAPH_SIN :DEGREES :JUMP
PU
MAKE "HORIZONTALMOVE 1
SETSPEED .9
INITIALPOSITION
SETSPEED 1
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_ELEMENTS 1
PU
]
END

TO BLUE&RED_ELEMENTS :SPEED
PD
REPEAT 1 [
;PRINT "BLUE
ROTATE_ELEMENT 10 10 "BLUE 30 :SPEED
;PRINT "RED
RT 90
ROTATE_ELEMENT 10 10 "RED 30 :SPEED
LT 90
]
END

TO TRACING
TRACE [ELEMENT]
TRACE [X&Y_AXIS]
TRACE [ROTATE_ELEMENT]
TRACE [BLUE&RED_ELEMENTS]
TRACE [FILL_COLOR]
END

TO UNTRACING
UNTRACE [ELEMENT]
UNTRACE [X&Y_AXIS]
UNTRACE [ROTATE_ELEMENT]
UNTRACE [BLUE&RED_ELEMENTS]
UNTRACE [FILL_COLOR]
END

;Main program

TO MAIN
PREPARE
TRACING
PRINT "Running!
PRINT "Low.Speed
ST
PU
SETSPEED 0.3
FD 10
LT 90
ELEMENT 3 160 .9 "BLACK 3 1
RT 90 FD 180 RT 90 FD 25
ELEMENT 4 150 .9 "RED 12 1
FD 370 RT 90 FD 370 RT 90
ELEMENT 5 180 .9  "ORANGE 30 1
FD 550 RT 90 FD 55 LT 90
ROTATE_ELEMENT 3 12 "GREEN 80 .9
ST
PU
GRAPH_SIN 360 2 3
ST
SETSPEED 0.9
INITIALPOSITION
BLUE&RED_ELEMENTS .9
ST
UNTRACING
PRINT "Combining.the.procedures
PRINT "At.high.speed!
MOVE_GRAPH_SIN 720 1
SETPC 0
PRINT "End.of.main.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