Lesson 2: Strings and Images
Overview
To compute more than just numbers, students will need to learn about two new data types, Strings (any string of alphanumeric characters) and Images. Using these new data types, we'll compose programs that produce and manipulate images.
Purpose
The programming language we are using in this course is a strongly typed language, meaning that we must explicity identify the types of data we're using.
Agenda
Getting Started
Activity: Strings and Images
Anchor Standard
Common Core Math Standards
- A.SSE.1 - Interpret expressions that represent a quantity in terms of its context.
Objectives
Students will be able to:
- Write and evaluate expressions for generating Strings and Images.
Vocabulary
- Data Type - All values in a programming language have a "type" - such as a Number, Boolean, or String - that dictates how the computer will interpret it. For example 7+5 is interpreted differently from "7"+"5"
- Image - A type of data used for graphics or pictures.
- String - Any sequence of characters between quotation marks (ex: "hello", "42", "this is a string!").
Support
Report a Bug
Teaching Guide
Getting Started
Introduction
In the previous stage, students only worked with a single type of value - Numbers. In this next stage they will get a chance to write programs with new data types to output text (Strings) and pictures (Images).
Show students the 'star' function, and ask them to discuss the following questions:
- What is the name of this function?
- How many arguments are being given to this function?
- What do you think this function will do?
Students are not expected to know all the answers here - the goal is for them to apply what they know about Evaluation Blocks to a novel expression, and discuss for themselves what they think it might mean. Ask them to justify their answers, and to explain why they think they are correct. Encourage students to look for patterns among these new blocks (such as colors, or quotation marks around the words "solid" and "purple" - what might those patterns mean?
Activity: Strings and Images
Online Puzzles
In this activity you'll use the new data types String and Image to compose art with Blocks of Evaluation - head to Course A Stage 2 in Code Studio to get started programming.
Student Instructions
So far we've only dealt with a single type of data, Numbers. Another type of data is a String, which is any combination of letters, numbers, or other characters wrapped in quotation marks. Run the String "Hello, world!" and see what happens.
Student Instructions
The string-append
function takes two Strings and returns a single combined String. Add a String "Universe" to the second argument of string-append
.
Student Instructions
The third type of data we're going to use is an Image. This star
function takes in a Number and two Strings, and it evaluates to an Image. Use this function to make a solid red star with radius of 100.
Student Instructions
Free Play: Every Evaluation Block is color-coded to let you know which data type it returns and which types it needs for its parameters. The last parameter of the triangle function takes a String that controls its color - try some different colors to see what works.
Student Instructions
Some functions can only take a specific set of Strings, such as the second argument of this circle
function, which controls its style. Draw this orange outline circle using the special String block with a dropdown to make sure you only use valid styles.
Student Instructions
Try using the rectangle
block to draw this solid, red rectangle - it is 175 pixels wide and 100 pixels tall.
Student Instructions
Try using this new Evaluation Block called overlay
to place a 100 pixel white triangle on top of a 200 pixel red circle.
Student Instructions
Use the overlay block to place a 75 pixel radius yellow star on top of a 150 pixel long blue square.
Student Instructions
The offset
block lets you move an image relative to where it would normally be placed. Use this block to offset the square by 100 pixels on the y-axis.
Student Instructions
Here's a different kind of star block - it's called radial-star
and it allows you to draw stars with any number of points! Use it to create a 7 point solid orange star with an inner radius of 75 pixels and an outer radius of 175 pixels.
Student Instructions
Student Instructions
Free Play: Explore the blocks available to create something interesting. Make sure to share your favorite creations.
Standards Alignment
View full course alignment
Common Core Math Standards
EE - Expressions And Equations
- 6.EE.9 - Use variables to represent two quantities in a real-world problem that change in relationship to one another; write an equation to express one quantity, thought of as the dependent variable, in terms of the other quantity, thought of as the independent va
- 7.EE.4 - Use variables to represent quantities in a real-world or mathematical problem, and construct simple equations and inequalities to solve problems by reasoning about the quantities.
F - Functions
- 8.F.1 - Understand that a function is a rule that assigns to each input exactly one output. The graph of a function is the set of ordered pairs consisting of an input and the corresponding output.1
- 8.F.2 - Compare properties of two functions each represented in a different way (algebraically, graphically, numerically in tables, or by verbal descriptions). For example, given a linear function represented by a table of values and a linear function represented
IF - Interpreting Functions
- F.IF.1 - Understand that a function from one set (called the domain) to another set (called the range) assigns to each element of the domain exactly one element of the range. If f is a function and x is an element of its domain, then f(x) denotes the output of f c
MP - Math Practices
- MP.1 - Make sense of problems and persevere in solving them
- MP.2 - Reason abstractly and quantitatively
- MP.3 - Construct viable arguments and critique the reasoning of others
- MP.4 - Model with mathematics
- MP.5 - Use appropriate tools strategically
- MP.6 - Attend to precision
- MP.7 - Look for and make use of structure
- MP.8 - Look for and express regularity in repeated reasoning
NS - The Number System
- 6.NS.8 - Solve real-world and mathematical problems by graphing points in all four quadrants of the coordinate plane. Include use of coordinates and absolute value to find distances between points with the same first coordinate or the same second coordinate.
OA - Operations And Algebraic Thinking
- 5.OA.1 - Use parentheses, brackets, or braces in numerical expressions, and evaluate expressions with these symbols.
- 5.OA.2 - Write simple expressions that record calculations with numbers, and interpret numerical expressions without evaluating them. For example, express the calculation “add 8 and 7, then multiply by 2” as 2 × (8 + 7). Recognize that 3 × (18932 + 921) is three t
Q - Quantities
- N.Q.1 - Use units as a way to understand problems and to guide the solution of multi-step problems; choose and interpret units consistently in formulas; choose and interpret the scale and the origin in graphs and data displays.
- N.Q.2 - Define appropriate quantities for the purpose of descriptive modeling.
REI - Reasoning With Equations And Inequalities
- A.REI.1 - Explain each step in solving a simple equation as following from the equality of numbers asserted at the previous step, starting from the assumption that the original equation has a solution. Construct a viable argument to justify a solution method.
SSE - Seeing Structure In Expressions
- A.SSE.1 - Interpret expressions that represent a quantity in terms of its context.
- A.SSE.2 - Use the structure of an expression to identify ways to rewrite it. For example, see x4 – y4 as (x2)2 – (y2)2, thus recognizing it as a difference of squares that can be factored as (x2 – y2)(x2 + y2).
- A.SSE.4 - Derive the formula for the sum of a finite geometric series (when the common ratio is not 1), and use the formula to solve problems. For example, calculate mortgage payments.★