Processing Each Item in a List
Ruthless Suggestions from Al
- The [lab] title: “Using Variables and Data Structures to Make Art”—Data Structures are all over this, but I see no use of “variable.” Radical suggestion: Maybe this won’t work, but can we save “variable” for things that get assigned and use “input” for things that get passed in when a command or reporter is called?
- The title has already been changed, but I kept the comment because of the question. Thoughts, Brian? --MF, 5/16/18
- Radical suggestion: Do we need to declare data types? It’s just one more thing for the user to track.
- No, but we do it in our blocks, so we thought we should show how it's done. I think it should be in a yellow box. Brian, why did you opt for green? --MF, 5/16/18
- PG: Simplify. Content feels important. I agree with Mary's handling of Rad sug #2. I bet it was me, not Brian, who went green on this, but not because I thought that was essential. Yellow is fine. I'd rather see it altogether in a "click if you feel like" block, whose surface shows the change and says something like "if you want to know how..."
- # 1: What does it mean: “Load and build their go to point block.” And when I load it, I see a list.
- I think this just needs some clarification. --MF, 5/16/18
This page is long. I suggest we consider breaking page between 2 and TOL and again between TIF and 7--making this into 3 separate pages. --MF, 9/26/18
Need to replace problem decomposition with modularity per AAP-3.B.2 and AAP-3.B.2. See vocab box on
3.2.4, Selecting Specific Data. (Appears on pages U2 furture OP Diagonal Design (mandala); 3.1.4, brick wall; 2.OP.4, plurals 1; and TG for 2.2 and 2.OP) --MF, 4/9/19
VAGUE OUTLINE FOR NEW VERSION
In this lab, you will create tools for drawing complex designs from lists of points. To do this, you will use modularity—breaking down the problem into smaller pieces.
On this page, you will create a script that lets you connect the dots (given by a list of points) to draw the letter A.
Alphie and Betsy are building a program that will take a list of points as input and connect the dots. They sketched the letter A on graph paper and listed the vertices.
Need to integrate this content pulled from 1.2 somewhere in this lab. --MF, 5/17/19
Locations on the stage (the white rectangle where sprites perform their scripts) are specified by
coordinates. The center of the stage is (0, 0). The left edge is
x = -240; the right edge is
x = 240. The bottom and top are
y = -180 and
y = 180.
I like this text and woner if we would use it elsewhere:
Yes, you can make your blocks show what type of data they expect as inputs: a number, a list, or some other type. Some languages require the data type to be indicated. In Snap! it's an option. It's not necessary but, like assigning a color to a block, it can be a helpful reminder of what the block does and what type of input it expects. You've already seen input slots of several shapes, indicating different expected data types.
Computers can help us collect data. Sometimes, we want to pull the data off of an image: of a graph, a letter, the coordinates of features of a face, the measurements of some bridge…. This lesson shows how to import an image and digitize particular points that can later be used to reproduce the image or be processed in some other way. (From PG)
write a program so that if we have a picture, we can click on the corners and let the program collect the coordinates
we can import images as a stage background
intro to collecting points as data
OLD VERSION FOLLOWS
In this lab, you will create tools for drawing complex designs from lists of points. To do this, you will use problem decomposition—breaking down the problem into smaller pieces.
On this page, you will create a script that lets you connect the dots (given by a list of points) to draw the letter A.
Alphie and Betsy are building a program that will take a list of points (each of which is a list of x and y coordinates) as input and connect the dots. They figure they can use it to draw pictures or graphs of data:
To make a set of starting data, they sketched the letter A on graph paper. They chose a scale that they figured would make their picture a good size on the stage.
ST-Many NYC teachers were confused and thought they are creating the list A themselves whereas we give it to them in the starter file.
Then they listed the coordinates of each vertex, starting at the arrow and going clockwise around the figure. The first point is at (-50, 20), the second is (-10, 120), and so on. Then they built that list in Snap
! like this:
Now they need a script that will use that list to make the drawing, like this:
Betsy: This list of coordinates outlines an A, so let's name it A.
Betsy clicks Make a variable
, names it A
, and builds .
Then she clicks that set
block to run it.
Alphie: So, for each of those eight points, we want the sprite to move to it. HM...
won't work, because it needs two separate inputs. We need a block that takes
one input, a point like
.
Betsy: So we'll make a
new block. Let's call it
go to point
. It'll work like this
. We'll use
or
inside it, but we'll have to process the input,
, to supply
x:
and
y:
separately. Hmmm...
Gamal: Oh! I know how! I bet we can use
. Give it a number as its first input. I bet that the
just says that it expects a list as its second input.
Alphie: I wonder if we can make our go to point
block show that it expects a list as input....
Need to integrate this content pulled from 1.2 somewhere in this lab. --MF, 5/17/19
Locations on the stage (the white rectangle where sprites perform their scripts) are specified by
coordinates. The center of the stage is (0, 0). The left edge is
x = -240; the right edge is
x = 240. The bottom and top are
y = -180 and
y = 180.
Yes, you can make your blocks show what type of data they expect as inputs: a number, a list, or some other type. Some languages require the data type to be indicated. In Snap! it's an option. It's not necessary but, like assigning a color to a block, it can be a helpful reminder of what the block does and what type of input it expects. You've already seen input slots of several shapes, indicating different expected data types.
This project file contains the list of points for the letter A, but you need to build their go to point
block that takes a point as input.
Specifying an Input Type
This animation shows you how to specify the list input type (
). Other input types are specified the same way.
Notice in the video that there are many input types you can specify (Text, Number, Boolean, etc.) The
list input type is chosen because a point is a
list of two coordinates.
After creating the title and naming the input,
-
Click on the arrow to the right of the input name:
- Choose the data type you want for that input.
- Click OK.
- Finish building your
go to point
block and test your block with a few points as input to make sure it does what you want it to.
First two bullets of AAP-2.N.1
- The list expression would be written as
point[2]
.
- The assignment instruction would be written as
verticalPosition ← point[2]
.
We could add APblocktran images here too. --MF, 4/19/19
Suggest page break.
Brian now agrees with having a page break here. --MF, 12/19/18 OTOH we should decide if we want to take advantage of Snap!'s ability to take lists in GO TO.
Alphie: Great! Now we can use our go to point
block for each of the points in our list.
Betsy: I bet we can use
.
Alphie and Betsy design this new script to automate the process of going to each point.
Then they test it out.
Alphie: Yup! for each
does exactly what we want. But we have a couple of bugs to fix.
- Build and test the script they used.
- Fix the two bugs Alphie noticed.
"U2L2-DrawShape"
-
Think and write:
- For what purposes might you not want to connect the first and last points?
- For what purposes might you want to have the pen down only when the sprite marks each point, but never when the sprite moves from one point to another?
- For what purposes might you prefer
go to
over glide
?
-
Create three new points and a script that draws the complete letter A. You'll have to design a way to indicate in a list of points that they aren't all connected.
Choose the additional coordinates yourself.