π Question of the Day
Fun Fact: In programming, "bugs" are errors in code. The term dates back to 1947 when an actual moth was found causing problems in a computer at Harvard University!
Alternative Thoughtful Question:
Sample Answer: Both require planning and creativity. In a story, you create characters, settings, and plot. In a game, you create sprites, backgrounds, and gameplay mechanics. Both need a beginning (setup), middle (action/story), and consideration for how everything works together. Just as an author revises their writing, programmers test and debug their code.
π₯ Video Activity
Watch Before Coding: Introduction to p5play
Video Title: "Getting Started with p5play - Canvas and Drawing Basics"
Recommended CodeHS Video: Introduction to p5play (Canvas Setup)
Duration: Approximately 5-8 minutes
Topics Covered:
- Creating a canvas with new Canvas()
- Understanding setup() and draw() functions
- Adding backgrounds and colors
- Basic coordinate system
- Introduction to Game Design β Unit 1: Canvas Basics
- JavaScript and Graphics β p5play Introduction
- Custom course videos you've assigned
π Quiz Answer Key
Total Points: 50 (10 points per question)
new Canvas(width, height); with width first, then height. Option B reverses the order, option C has incorrect syntax with a period after "new", and option D uses the wrong order with "Canvas.new" instead of "new Canvas".
clear(); background('red'); 10 Points
clear() function removes all previously drawn graphics from the canvas, and background('red') fills the canvas with a red background color. This is done in the draw() function to refresh the screen each frame, preventing "ghost images" or trails. It doesn't clear the entire web page (A), doesn't affect borders (B), and doesn't clear variables (D).
π‘ Reflection Question Sample Answers
Question 1: Why is it helpful to use the setup() and draw() functions in your program?
Sample Answer: Using setup() and draw() functions helps organize the code and makes it easier to understand. The setup() function runs once at the beginning, which is perfect for creating the canvas and setting up initial values. The draw() function runs repeatedly, which is necessary for animation and updating the game continuously. This separation makes the code cleaner and follows the structure that all p5play programs use.
Key Points Students Should Mention:
- setup() runs once / draw() runs repeatedly
- Helps organize code / Makes code structure clear
- setup() for initialization / draw() for animation
- Standard structure for game programming
Question 2: How might knowing your mouse coordinates help you later when adding sprites and obstacles?
Sample Answer: Knowing the mouse coordinates helps me figure out exactly where to place sprites and obstacles on the canvas. Instead of guessing positions, I can move my mouse to where I want something to appear and see the exact X and Y coordinates. This makes it much easier to position the golf ball, hole, walls, and obstacles precisely where I want them. It saves time because I don't have to keep testing different numbers to get the placement right.
Key Points Students Should Mention:
- Helps with accurate/precise positioning
- Eliminates guessing coordinates
- Saves time during design process
- Makes it easier to place game elements
- Helps with testing and debugging placement
β Student Checklist - Grading Criteria
| Task | Points | What to Look For |
|---|---|---|
| Program structure created | 10 pts | Both setup() and draw() functions are present and properly formatted |
| Canvas created & visible | 15 pts | new Canvas(450, 520); appears in setup(), canvas displays when run |
| Background color added | 10 pts | clear() and background() are in draw() function, color displays |
| (Optional) Mouse coordinates display | 10 pts | If attempted: coordinates variable declared, functions implemented correctly |
| Reflection questions completed | 15 pts | Both questions answered with thoughtful, complete responses |
| TOTAL | 60 pts | Plus 50 pts for quiz = 110 total points |
π» Complete Code Solution
What Each Part Does:
π Teaching Tips & Common Student Mistakes
Common Mistakes to Watch For:
- Forgetting semicolons at the end of lines
- Misspelling "Canvas" (capital C matters!)
- Reversing width and height in Canvas()
- Forgetting curly braces { } for functions
- Putting canvas creation in draw() instead of setup()
- Forgetting clear() before background() (causes visual issues)
- Not declaring variables at the top of the program
- Calling mouseCoordinates() in draw() instead of setup()
Extension Activities:
For Advanced Students:
- Try different canvas sizes and see how it affects the display
- Experiment with different background colors (hex codes, RGB, color names)
- Make the coordinate display follow the mouse pointer
- Add a second text display showing the canvas dimensions
- Create a gradient background using multiple colors