1/23
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Compound Conditionals
Conditionals that use the keywords ‘and’, ‘or’, or ‘not’ to check for multiple conditions.
When are ‘and’ compound conditionals true?
Only when both conditions are met.
When are ‘or’ compound conditionals true?
Applies when at least one conditional is met.
What does ‘inclusive or’ mean?
The entire ‘or’ compound conditional is true if one or both of the specified conditions are true.
‘not’ conditionals
Works when a condition is false.
Nested Conditionals
Conditions within conditions that only run when the outside condition(s) are true and the current condition is true.
What is ‘onStep’ used for and what does it do?
A function within CMU that allows for the app to continually change even when the user isn’t directly interacting with it (ex: mouse or keyboard press) and is primarily used to animate shapes.
How many times is ‘onStep’ called by default?
30 times per second.
What property would you use in ‘onStep’ to increase or decrease the # of times per second?
app.stepsPerSecond
Increasing it makes animations faster.
Decreasing it makes animations slower.
What is ‘dx’ in horizontal motion?
Its basically a value that stores how much an object’s centerX changes by for each step within onStep, and it controls the velocity of the object within the x-axis.
What is ‘dy’ in vertical motion?
Its basically a value that stores how much an object’s centerY changes by for each step within onStep, and it controls the velocity of the object within the y-axis.
How is an object’s movement affected when:
dx is positive.
dx is negative.
Object moves continuously towards the right.
Object moves continuously towards the left.
How can you reverse the horizontal motion of an object using dx?
Use this syntax: ‘player.dx = -player.dx’ → basically, negate the dx value to change directions.
How can you make an object stand still using dx?
Set dx = 0, but keep adding it to the object’s centerX.
How can you include ‘bounded motion’ for an object using dx?
When the object reaches the left or right edges of the canvas, set dx = 0 to make it stand still.
How can you include ‘wraparound motion’ for an object using dx?
When the object reaches one end of the canvas, set its centerX to appear outside of the other end to make it “reappear”.
How can you include ‘bouncing motion’ for an object using dx?
Negate the dx attribute (reverse direction) when the object reaches the ends of the screen.
How is an object’s movement affected when:
dy is positive.
dy is negative.
Moves down the canvas.
Moves up the canvas.
How can you reverse the vertical motion of an object using dy?
Similar to dx, negate the dy attribute using: “player.dy = -player.dy”
How can we manipulate dy to achieve the following:
Make the object stand still on the y-axis
Bounded Motion
Wraparound Motion
Bouncing Motion
Set dy = 0.
When the object reaches the upper/lower bound of the canvas, set dy = 0.
When the object passes through one end of the canvas, set its centerY outside of the other bound to make it “reappear”.
When the object touches an edge, negate dy (reverse its direction).
How can you achieve diagonal movement with dx and dy?
Manipulate both dx and dy at the same time (ie. dx and dy cannot both be 0) but they don’t have to be the same.
What does ‘random.randint(min, max)’ do?
Generates a random number between the min and max parameters, with the min and max also included.
What does ‘random.choice(listName)’ do?
Randomly selects an item from the specified list.
What is a way we can retrieve random items from a list without using random.choice()?
Use listName[random.randint(0, len(listName) - 1)] to randomly select a value within the list.