AP CSP CodeX - Mission 14: Line Art
Mission 14: Line Art
Students use pixels, loops and functions to draw string art on the CodeX display.
Overview
In this mission, students use computer graphics to create string art on the CodeX display. They start by setting single pixels, then use loops, the step parameter and nested loops to draw axes and a grid. Next they draw lines with display.draw_line() and build an envelope (a web pattern) with a loop and a custom function. The coding can be finished in one class period, but two days leaves time for discussion and the challenges.
🎯 Mission Goal: Students will use computer graphics to create beautiful string art.
Learning Targets
- I can use pixels to draw a line on my LCD screen.
- I can use the bitmap function to get display width and height.
- I can explain how to convert a number from a float to an integer.
- I can use a loop to create a pixel grid on the LCD.
-
I can draw an envelope (webbing) using the
display.draw_line()function.
Key Concepts
- The CodeX display screen is a bitmap, and every bitmap has a width and height.
- Using built-in line drawing functions is faster, simpler and supports drawing diagonal lines.
- One way to optimize code is to replace many lines of code that draw lines with a function instead.
- Creating string art is easy by using an envelope, a loop and a constant.
- Defining a custom function with line points that spin counterclockwise makes a web pattern.
Assessment Opportunities
Success Criteria
- Draw an x- and y-axis on the display screen
- Draw a white grid of dots on the display screen
- Draw a blue square as a border around the screen
-
Use built-in screen information for drawing lines (
display.widthanddisplay.height) - Create a function for drawing a web
- Call the web function at least 6 times
Digital Resources
- ▸Mission 14 Assignment
- ▸Mission 14 Obj. 1-5 Kahoot! Review
- ▸Mission 14 Obj. 6-9 Kahoot! Review
- ▸Code Solutions and Assignment Answers - Teacher Dashboard > Educator Resources button
Classroom Materials
- ▸CodeX
- ▸USB-C cable
- ▸Computer
Real-World Applications
Extensions & Cross-Curricular
display.width / 2 gives 120.0 and what int() does to it.
get_pixel() returns and explain how it makes cyan.
🔤
Vocabulary
▾
🐍
New Python Code
▾
📐
Standards
▾
CSTA Standards - Grades 9-10
CSTA Standards - Grades 11-12
AP CSP Framework
- The assignment is best completed digitally. Prepare the assignment to give through your LMS.
- Plan for one or two class periods. If you split the mission, stop after Objective 5 on day one and have the Mission 14 Obj. 1-5 Kahoot! Review ready.
- Have the Mission 14 Obj. 6-9 Kahoot! Review ready for day two.
- If you have a word wall, or another form of vocabulary presentation, prepare the new terms.
- This can be a one or two day assignment. Your students can probably finish the mission as-is in one day. However, if you want to take two days, you will have time for discussion. Students can also add functionality to the program, like a remix, with the challenges. This gives them an opportunity to practice programming concepts learned earlier on a new project.
- The math for the envelopes can look complicated. Students do not need to understand it. The main idea is selecting a beginning and ending position for each line point. Experimentation is fine. The finished picture does not have to look like anything in particular.
- Encourage the students to do as much code on their own as they can, and use CodeTrek to check their work, or as a hint when needed.
- The assignment adds an extra step to complete after Objective 9, and a challenge.
- If students are interested in creating their own bitmap images (like pixel art), you can find the lesson "CodeX and ASCII Art" in the additional CodeX projects.
- Refer to the lesson plans in the Python with CodeX Mission Pack Curriculum for additional challenges, cross-curricular suggestions and additional information.
Lesson Outline
This outline gives the narration for one way to present the lesson.
In previous missions and lessons, you learned to draw using lines, circles and rectangles. How do you think you can use them in loops to create art? Have a brief discussion.
Randomly group students into pairs for pair programming (or they can work individually).
Students log in to one computer. Two computers can be used if they want to have the assignment open on one computer and CodeSpace on the other computer.
Students go to make.firialabs.com and should be at the beginning of Mission 14.
print().NOTE: Students answer the question "What can you do to avoid magic numbers?" The answer can be straight from the textbook (get the display width and height straight from the source), or more general, like using variables and constants to represent the numbers. The goal in the objective is to eliminate magic numbers by using the functions rather than literal numbers. You can remind students that a literal number IS a magic number.
NOTE: Running the code WILL cause an error. Students may realize it is because of the type of division.
//) will work nicely, but the validator will check that the int() function is used.If this is the end of your class period, you can do a wrap-up with the Mission 14 Obj. 1-5 Kahoot! Review.
Continue either in pairs or individually. Students go to make.firialabs.com and should be on Objective 6 of Mission 14.
display.draw_line() and reviews display.draw_rect(). It should be review for most of your students. Go over any of this material as needed.NOTE: Students are asked to do a "Save As" and give the file a new name. This keeps the original file and starts a new file with code already there. They will delete some code from the new file before adding more. If they do not do the "Save As", it is okay. They just will not keep their original code.
This objective shows students how to use a for loop to draw the lines to create the web. After they create the for loop, run the program. Then they change the value of WEB_SPACING and run again to meet all the goals. CodeTrek uses literal numbers for 120 and 239. After Objective 9, students are asked to use the variables to replace the magic numbers.
Then students create the function and replace the for loops with function calls. Four function calls are provided. Students must call the function two more times. They can try to complete the webs that are drawn, but they do not have to. Any two function calls will meet the goal. The solution provided shows the completed webbings as a possible solution.
The assignment is complete and ready to turn in.
The post-mission reflection asks students to think about using their creativity and working through frustration. You can change the questions if there is something else you want to emphasize with your students.
Discussion: You have learned a lot about pixel art! How did you use your creativity to complete the program? This program can be frustrating. How did you manage your frustrations and work through problems?
Students complete the wrap-up questions on the assignment. You can have a short discussion on their answers.
Optional. Use a formative assessment for the wrap-up.
Formative assessment:
- Daily reflection journal
- Mission 14 Obj. 1-5 Kahoot! Review
- Mission 14 Obj. 6-9 Kahoot! Review (in class or individual)
- Exit ticket on display functions
- Exit ticket on for loops and the step parameter