Draft Unit 2 Lab 2 Using Variables and Data Structures to Make Art Page 4 Key

ST EK List:
5.2.1E Program execution automates processes.
5.5.1H Computational methods may use lists and collections to solve problems.

Processing Each Item in a List

Ruthless Suggestions from Al

  • The [lab] title: "Using Variables and Data Structures to Brand Art"—Information Structures are all over this, only I see no use of "variable." Radical suggestion: Maybe this won't piece of 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 championship has already been inverse, merely I kept the comment considering of the question. Thoughts, Brian? --MF, v/16/18
  • Radical suggestion: Do we need to declare information types? It's only one more thing for the user to runway.
    • No, but we do it in our blocks, so we thought we should testify how information technology's washed. I think it should be in a yellow box. Brian, why did yous opt for light-green? --MF, five/16/xviii
  • # 1: What does it mean: "Load and build their go to betoken block." And when I load it, I meet a listing.
    • I think this but needs some clarification. --MF, v/16/18

This project has for each already imported. The folio should be clear that students volition have to import tools if they want to use for each in their own projects. --MF, eleven/15/17

decagon-mandala-ring-and-outline-of-letter-A

In this lab, you will create tools for drawing complex designs from lists of points. To do this, y'all will use problem decomposition—breaking downwardly the problem into smaller pieces.

On this page, you lot volition create a script that lets yous connect the dots (given by a list of points) to draw the letter A.

Alphie and Betsy are edifice a programme that will take a list of points (each of which is a list of x and y coordinates) equally input and connect the dots. They figure they can apply information technology to depict pictures or graphs of data:

To make a gear up 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 idea they are creating the list A themselves whereas we requite it to them in the starter file.

Letter A drawn of graph paper with corner coordinates Corner coordinates (-50, 20) (-10,120), ... (-30,20)
Then they listed the coordinates of each vertex, starting at the pointer and going clockwise effectually the figure. The first point is at (-l, xx), the 2d is (-ten, 120), and and then on. Then they built that listing in Snap! like this:
coordinate-list-for-A
Now they need a script that will employ that list to make the drawing, like this:

Betsy: This listing of coordinates outlines an A, and so let's name it A.

Betsy clicks Make a variable, names it A, and builds set A to {{-50,20}, {-10,120}, {10,120}, {50,20}, {30,20}, {20,50}, {-20,50}, {-30,20}}.

Then she clicks that gear up block to run it.

Alphie: So, for each of those eight points, we want the sprite to motion to it. Hmmm... go to x:() y:() won't work, because information technology needs 2 separate inputs. Nosotros need a block that takes ane input, a point like list(-50)(20).

Betsy: And then nosotros'll brand a new block. Let's call it get to point. Information technology'll work like this go to point (list (-50) (20)). We'll use go to x:() y:() or glide (.5) secs to x:() y:() within it, but we'll take to process the input, list(-50)(20), to supply x: and y: separately. Hmmm...

Gamal: Oh! I know how! I bet nosotros tin can utilize item()of(list). Give information technology a number every bit its first input. I bet that the rectangle with two smaller orange rectangles inside just says that it expects a list every bit its second input.

Alphie: I wonder if nosotros can brand our go to point cake show that information technology expects a list as input....

Yes, you can make your blocks testify what blazon of data they expect as inputs: a number, a listing, or some other blazon. Some languages require the information type to be indicated. In Snap! information technology's an choice. It'due south not necessary but, similar assigning a colour to a block, information technology tin exist a helpful reminder of what the cake does and what type of input it expects. You've already seen input slots of several shapes, indicating different expected data types.

Notice in the video that there are many input types you can specify (Text, Number, Boolean, etc.) The list input type is chosen considering a indicate is a list of 2 coordinates.
Input types, list type selected

  1. Click here to load this file. Then save it to your Snap! account.
    It contains the listing of points, but you lot need to build their go to point (point) block with list type input named point block.
  2. Specifying an Input Type

    This animation shows yous how to specify the list input type. Other input types are specified the same way. list input type: rectangle with two smaller orange rectangles inside

    After creating the championship and naming the input,

    • Click on the arrow to the right of the input name:
      create input name right arrow
    • Choose the information type y'all want for that input.
    • Click OK.
  3. Finish edifice your get to point cake and test your block with a few points as input to make sure it does what y'all want information technology to.

Alphie: Groovy! At present nosotros tin can use our go to point block for each of the points in our list.

Betsy: I bet we can use for-each-(item)-of(){}.

Alphie and Betsy design this new script to automate the process of going to each signal.

pen down;for each(item) of (A){go to point(item)}

And so they test it out.

Alphie: Yup! for each does exactly what nosotros desire. Simply we have a couple of bugs to fix.

  1. Build and examination the script they used.
  2. Prepare the two bugs Alphie noticed.
  3. "U2L2-DrawShape" Save your work as U2L2-DrawShape

  4. Think and write:
    • For what purposes might y'all not want to connect the beginning and concluding points?
    • For what purposes might y'all want to accept the pen down merely when the sprite marks each bespeak, simply never when the sprite moves from ane point to some other?
    • For what purposes might you lot prefer go to over glide?
  1. Create three new points and a script that draws the complete letter A. Y'all'll have to pattern a way to indicate in a listing of points that they aren't all connected.

    Choose the additional coordinates yourself.

    complete-drawing-of-letter-A

Self-Check: For Each

  1. These questions are similar to those you will encounter on the AP CSP exam.
    inputList ← [3, -1, ii, 10, -5]  FOR EACH item IN inputList {	   IF ( (item > 0)  AND  (detail * item > 4) )   {     DISPLAY detail   } }                  

    What volition be displayed every bit a issue of running the lawmaking segment given?

    9, 1, 4, 100, 25

    ix, 100

    Procedure Mystery (numberList, targetNumber) {   counter ← 0   FOR EACH number IN numberList   {     IF (number > targetNumber)     {       counter ← counter + one     }   }   Return (counter) } myMathGrades ← [100, 80, ninety, 80, 60, 100, l, 100] Mystery(myMathGrades, lx)                  

    What will be returned if the code to a higher place is run?

    [100, eighty, 90, 80, 100, 100]

    60

solomoncrian1947.blogspot.com

Source: https://bjc.edc.org/March2019/bjc-r/cur/programming/2-complexity/2-data-structures-art/1-the-for-each-block.html?topic=nyc_bjc%2F2-conditionals-abstraction.topic&course=bjc4nyc.html&novideo&noassignment

0 Response to "Draft Unit 2 Lab 2 Using Variables and Data Structures to Make Art Page 4 Key"

Postar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel