Info Packet - the children have the printed packet | Code.Wolrd
1) polyline Now you can draw things like sequences of lines by giving a list of points in the coordinate plane to a function called polyline:
program = drawingOf(zigzag)
zigzag = polyline([(-2, 0), (-1, 1), (0, -1), (1, 1), (2, 0)])
The square brackets form something called a list. You haven't seen lists before, but they are just what they sound like: collections of multiple things in order. When drawing lines and polygons, you will place your points in a list (in square brackets) before giving them to the function.
2) polygon To draw a closed shape, which ends back where it started, you can use polygon instead. Can you figure out the mystery picture before you run it?
program = drawingOf(mystery)
mystery = polygon(
[(-3, -4), (0, 5), (3, -4), (-4, 2), (4, 2), (-3, -4)])
3) solidPolygon If you prefer to fill in your shape, you can use solidPolygon instead of polygon and you'll get a solid version.
program = drawingOf(mystery)
mystery = solidPolygon(
[(-3, -4), (0, 5), (3, -4), (-4, 2), (4, 2), (-3, -4)])
program = drawingOf(coordinatePlane & fullPic)
pic1 = polyline( [ (0,1), (3,4), (4,3), (1,0) ] )
& polyline( [(4,0), (7,3), (9,3), (10,2), (10,1), (9,0)] )
& polyline( [(3,4), (3,6), (5,9), (7,9), (9,7), (9,5), (6,3), (4,3)] )
& polyline( [(5,9), (5,7), (7,5), (9,5)] )
fullPic = pic1
-- Create pic2 by reflecting pic1 across y-axis (the line with the angle of 90 degree)
-- pic2 = reflected(pic1, 90)
--fullPic = pic1 & pic2
---------------------------
-- Add remaining lines:
-- (5,9) (5,7) (7,5) (9,5) STOP
-- (0,9) (1,6) (2,7) (1,4) (2,5) (0,1) STOP
-- (9,5) (8,7) (7,8) (6,8) (6,7) (7,6) (8,6) (7,7) STOP
-- (2,1) (3,1) (3,2) STOP
-- (6,6) (6,5) (5,5) (5,4) (4,4) (4,3) STOP]
--
Game 1 - Funny Eyes: Read the program below and decide which eye is eye1 and which one is eye2.
-- Easy example for you to COPY/PASTE (use these key combinations: Command-C and Command-V)
program = drawingOf(coordinatePlane & eyes)
cir1 = solidCircle(1)
eye = colored(cir1, green)
eye1 = translated(eye, 2,3)
eye2 = translated(eye, -2,3)
eyes = eye1 & eye2
Game 2 - Funny Eyes: Modify the "Eye" program:
add a third eye (Optional: Add more eyes)
change the eyes' color
add a mouth (e.g. a red cirlce)
add the head (a big circle)
The Monster Program - HELP
OPTIONAL: Unfold the hidden text below to see a sample code that draws a Monster ...
-- Easy example for you to COPY/PASTE
program = drawingOf(coordinatePlane & eyes & mouth & head)
cir1 = solidCircle(1)
eye = colored(cir1, green)
eye1 = translated(eye, 2,3)
eye2 = translated(eye, -2,3)
eye3 = translated(eye, -5,2)
eyes = eye1 & eye2 & eye3
mouthPre = dilated(cir1, 1.5)
mouth = solidRectangle(1, 0.5)
& colored(mouthPre, red)
-- headPre = solidCircle(7)
headPre = circle(7)
head = translated(headPre, 0, 2)
Game 1 - Moving Circles: Read the program below and decide which circle is cir2 and which one is cir3.
program = drawingOf (coordinatePlane & testCircles)
-- Initial circle (radius 1), ready for transformations (changes)
cir1 = circle(1)
-- -- MOVING Pictures with 'translated' function --
-- cir1 was translated (moved) 5 units horizontally and 2 units vertically
cir2 = translated(cir1, 5, 2)
-- cir3 is cir1 moved 3 units *down* (and 0 units horizontally)
cir3 = translated(cir1, 0, -3)
testCircles = cir2 & cir3
Game 2 - Coloring circles: Copy/past the program below, run it and modify:
change the color of cir2 (from green to your favorite color)
OPTIONAL: change the color of cir4 to dark blue
program = drawingOf (coordinatePlane & testCircles)
-- Initial circle (radius 1), ready for transformations (changes)
cir1 = solidCircle(1)
-- -- COLORING pictures with 'colored' function --
-- cir2 is cir1 colored red
cir2 = colored (cir1, green)
-- cir3 is cir1 moved 3 units *down* (and 0 units horizontally)
cir3 = translated (cir1, 0, -3)
-- cir4 is cir3 colored light blue
cir4 = colored (cir3, light(blue))
testCircles = cir2 & cir4
Game 3 - Snowman: Copy/past the program below, run it.
Change the color of our snowman
OPTIONAL: add eyes
program = drawingOf (coordinatePlane & snowman)
-- Initial circle (radius 1), ready for transformations (changes)
-- cir0 = solidCircle(1) & thickCircle(1.1, 0.04)
cir0 = solidCircle(1)
cir1 = colored (cir0, light(blue))
-- MOVING up the initial circle - translating
cirTop = translated (cir1, 0, 6.5)
-- Middle circle: enlarging cir1 and then moving it up
cir2 = dilated(cir1, 1.7)
cirMiddle = translated (cir2, 0, 4)
-- Resizing cir1: enlarging it 2.5 times
cirBottom = dilated (cir1, 2.5)
snowman = cirTop & cirMiddle & cirBottom
The Snowman Program - HELP
OPTIONAL: add eyes. Unfold the hidden text below to see some sample code that adds the eyes ...
eye = solidCircle(0.2)
eyes = translated(eye, 0.5, 7) &
translated(eye, -0.5, 7)
snowman = eyes & cirTop & cirMiddle & cirBottom