π Conditionals & Variables
Unit 1 β Algorithms and p5 | September 27Do Now (in p5)
- Create a canvas that is the size of the screen
- Create a shape (
ellipse()
,rect()
, etc) that follows your mouse - Write a conditional so that the
fill()
of the shape changes if the mouse is on the left or right side of the screen.
Like this:
Conditionals & Variables
Our next challenge is to make a sketch where a ball shape bounces around the screen.
This is a more complicated than the sketches weβve done so far, because we will be defining our own variables.
To figure out what variables we need, think about what needs to change so a shape looks like itβs bouncing. Letβs look at it:
A pile of π© moves across the screen. What changes?
- The
x position
of the shape - The
y position
of the shape
Now, the π© hits the edge of the screen. What changes?
- The
x direction
β if the shape hits the left edge, it should go right. If it hits the right edge, it should go left. - The
y direction
β if the shape hits the top, it should start moving down. If it hits the bottom, it should start moving up.
Specification | Points |
---|---|
Your canvas must resize to the window. |
1 |
User created variables | 3 |
Conditionals for the left/right and top/bottom edge of the screen | 1 |
Extension | β± |
Ball bounces using only 2 conditionals | 2 |
Total: | __ / 5 |