instagram

(Also available in WeScheme)

Students develop and define a function of their own. The function must take in an image and manipulate it using at least three transformations. This project supports the learning goals of Functions: Contracts, Examples & Definitions.

Lesson Goals

Students will be able to…​

  • represent function composition with Circles of Evaluation

  • use image-producing functions and functions that transform to define a function

Student-facing Lesson Goals

  • Let’s make our own functions in Pyret!

Materials

Preparation

  • Before launching this project, ensure that students are comfortable using image-producing functions and function composition.

  • Teachers are welcome and encouraged to edit and adapt the student-facing Rubric: Create Your Own Function for their unique classroom context and distribute it to help students understand the scope of the project - and your expectations - at the outset.

  • Decide how you will have your students submit their program links. Specify how you would like students to do this. Email, a form, or any SMS (i.e., Google Classroom or Schoology) will work!

Key Points for the Facilitator

  • This project is designed to span multiple days.

  • Note that, in addition to a published Pyret program link, students should submit their Sample Function Study, Designing Your Function and both Coding Your Function pages.

🔗Functions Refresher 15 minutes

Overview

Students explore two example functions. One is a basic function that will serve as a review of how Contracts, Examples and Definitions should work together and what we an learn from error messages. The other is a composed image function that should pique their curiosity in preparation for designing their own function.

Launch

  • What functions have we defined so far and what did they do?

    • Answers will vary, but may include:

    • gt made green equilateral triangles of any size.

    • bc made blue circles of any size.

    • sticker made a solid 50px star of a given color

    • gold-star made a gold star of any size

    • name-color made an image of your name at size 50 in whatever color is given

    • name-size made an image of your name in your specified favorite color in the given size…​

Investigate

Let’s take a look at the definition for a new function.

Complete the first section of the Functions Study using the Functions Study Starter File.

  • What did you have to fix to address the warnings for maroon-square?

    • We had to change the color in the definition from "orange" to "maroon".

Your are going to be defining a function of your own design that takes in an image, and transforms that image at least three times. Let’s look at a function like that!

Complete the second section of the Functions Study using the Functions Study Starter File,

  • What does the function mystery do?

    • It consumes an image, which will be scaled, rotated, and overlayed on a purple rectangle that is overlayed on a green star.

  • How are the maroon-square and mystery functions alike? How are they different?

    • Both functions produce images, but maroon-square consumes a number, while mystery consumes an image.

    • The function mystery is more complex: it uses a variety of composed functions, while maroon-square uses only one function.

Synthesize

  • When writing an example, how does a programmer decide what number to use as the input?

    • We can use any number, unless we’re trying to test for a special use-case.

  • When writing an example, how does a programmer decide what the output should be?

    • We can think about "what our actor would need to say".

    • We can look at the directions.

  • When writing a function definition, how does a programmer decide what the variable(s) should be?

    • We would look to see what changes.

  • What is the process for writing our function definition?

    • We look at the examples, write down everything that remained the same, and we replace the part that changes from one example to the next with a descriptive variable.

Before moving onto the next phase of the project, some teachers have students submit their work now, and evaluate it using the first row of the rubric. Intermittently receiving feedback is useful for many students.

🔗Create Your Own Function flexible

Overview

Students will design a function of their own and represent it with a Circle of Evaluation and code. Finally, they will publish and share their program.

Launch

It’s time to design your own image-transforming functions!

Turn to Designing Your Function. The questions on this page will help you plan out what you want to your image-transforming function to do, before we dig into writing the code to make it happen.

If students get stuck, you can refer them back to the mystery function in the Functions Study Starter File.

Note that if you are collecting student work intermittently, now is a good time to do so. This phase of the project can be evaluated according to the second row of the rubric.

Investigate

In this phase of the project, students begin to think more deeply about how they will write the code needed to produce their function. They also code and test their function in Pyret, before publishing and submitting.

  • If we were to draw a Circle of Evaluation for what the mystery function does with a shape it takes in, it would look like this:

(overlay (overlay (scale 0.5 (rotate 45 shape)) (rectangle 90 75 "solid" "purple")) (star 200 "solid" "teal"))

  • Find shape in the diagram. What do you Notice? What do you Wonder?

  • With your partner discuss how the Circle of Evaluation shows us what the function is doing with shape and then translate the Circle of Evaluation into code.

Code: overlay​(​overlay​(​scale​(​0.5, rotate​(​45, shape​)​), rectangle​(​90, 75, "solid", "purple"​)​), star​(​200, "solid", "teal"​)​)

  • Now turn to Represent Your Function with a Circle of Evaluation and draw a Circle of Evaluation to represent the function you’ve designed!

  • When you are finished, swap papers with a partner and complete the Peer Review on the bottom half of the page.

  • When you get your peer review back, make any necessary changes to your Circle of Evaluation.

Students who are able to conceptualize their function by drawing an accurate Circle of Evaluation will be able to progress through the remainder of the project much more confidently. It is vital to ensure that students have done adequate planning before they begin coding in Pyret. If you’d like, this is another good opportunity to assess student work using the third row of the rubric.

Coding Your Function asks students to define a value, add examples, and define their functions. They also complete a second round of peer review. When students are struggling, encourage them to read error messages carefully and refer to any relevant contracts.

  • Turn to Coding Your Function and translate your polished Circle of Evaluation into Code.

  • Then open the My Function Starter File and complete the second section of Coding Your Function.

  • When you finish, trade papers with your partner and complete the Peer Review section.

  • After you’ve polished your file, it’s time to submit it!

Synthesize

  • Think about the process of creating your own function. What was the most rewarding part? What was the most challenging part?

  • What advice would you offer to someone who was trying to design an image-transforming function, like you just did?

Encourage students to self-assess and revise their work. Peer review is a powerful tool if time allows! The rubric is a useful resource for facilitating both self and peer review.

Finally, celebrate students' work! In many instances, students will want to share their project, given how much time they have invested. Class or public presentations can instill a sense of pride.

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, 1738598, 2031479, and 1501927). CCbadge Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.