Back to AI Flashcard MakerInformation Technology /Animation and Games CodeHS Part 5

Animation and Games CodeHS Part 5

Information Technology11 CardsCreated 5 months ago

A set of flashcards covering key concepts from CodeHS Part 5: Animation and Games, including circles, shapes, and event handling.

How many circles of radius 10 will fit vertically stacked in a window that has height 100? The circles should not overlap, the bottom of one circle should touch the top of the next circle.

5

Tap or swipe ↕ to flip
Swipe ←→Navigate
1/11

Key Terms

Term
Definition

How many circles of radius 10 will fit vertically stacked in a window that has height 100? The circles should not overlap, the bottom of one circle should touch the top of the next circle.

5

This is a circle on our canvas named ball. What are the coordinates of point A?

ball.getX() + ball.getRadius(), ball.getY()

What statement should we use to determine if ball is hitting the bottom edge of the window?

if(ball.getY() + ball.getRadius() > getHeight()){
//ball is hitting bottom edge
}

How can we determine if ball's left edge is hitting a different shape on our canvas named box?

var elem = getElementAt(ball.getX() - ball.getRadius() - 1, ball.getY());
if(elem == box){
//ball's left edge is hitting box
}

The following code moves a ball across the screen at a rate of dx in the x direction and dy in the y direction.
...
What do we need to add to line 19 to have the ball bounce off the top of the window like this:

dy = -dy;

Which of the following statements will call the function paint every time the mouse is moved?

mouseMoveMethod(paint);

Related Flashcard Decks

Study Tips

  • Press F to enter focus mode for distraction-free studying
  • Review cards regularly to improve retention
  • Try to recall the answer before flipping the card
  • Share this deck with friends to study together
TermDefinition

How many circles of radius 10 will fit vertically stacked in a window that has height 100? The circles should not overlap, the bottom of one circle should touch the top of the next circle.

5

This is a circle on our canvas named ball. What are the coordinates of point A?

ball.getX() + ball.getRadius(), ball.getY()

What statement should we use to determine if ball is hitting the bottom edge of the window?

if(ball.getY() + ball.getRadius() > getHeight()){
//ball is hitting bottom edge
}

How can we determine if ball's left edge is hitting a different shape on our canvas named box?

var elem = getElementAt(ball.getX() - ball.getRadius() - 1, ball.getY());
if(elem == box){
//ball's left edge is hitting box
}

The following code moves a ball across the screen at a rate of dx in the x direction and dy in the y direction.
...
What do we need to add to line 19 to have the ball bounce off the top of the window like this:

dy = -dy;

Which of the following statements will call the function paint every time the mouse is moved?

mouseMoveMethod(paint);

What is a callback function?

A function passed to an event handler that is called every time a certain event happens

In the following statement:
mouseMoveMethod(draw);
Which part is the event handler?

mouseMoveMethod

In the following statement:
mouseMoveMethod(draw);
Which part is the callback function?

draw

In the following code:
function start(){
mouseUpMethod(paint);
}
function paint(e){
//code to paint something on the canvas ...
}
What is the meaning of e?

e is a parameter passed to the callback function paint that contains information about the Mouse Event, such as where on the window it occurred.

The following program adds several shapes to the screen.
function addShapes(){
//code that fills the screen with shapes
//don't worry about how it's implemented ...
}
function start(){
addShapes();
mouseClickMethod(removeShape);
}
We want to write a function that will remove any shape the user clicks on. Which of the following is the best implementation of the function removeShape?

function removeShape(e){
var shape = getElementAt(e.getX(), e.getY());
if(shape != null){
remove(shape);
}
}