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

Animation and Games CodeHS Part 2

Information Technology10 CardsCreated 5 months ago

This deck covers key concepts and functions from the CodeHS Animation and Games module, focusing on creating and manipulating shapes and handling events.

9.3.5: Circle Wall

This program creates a wall of circles across the canvas. Constants define the circle radius and the drawing delay. Global variables track the current x and y positions and a counter for coloring. The start() function sets a timer to repeatedly call the draw() function. The draw() function creates a circle at the current position and colors every other circle red. After adding the circle, the x-position increases to place the next circle, and when it reaches the canvas width, x resets and y moves down. This continues until the y-position exceeds the canvas height, at which point the timer stops. The result is a neatly spaced wall of alternating red and default-colored circles.

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

Key Terms

Term
Definition

9.3.5: Circle Wall

This program creates a wall of circles across the canvas. Constants define the circle radius and the drawing delay. Glob...

9.3.6: Brick Wall

This program builds a brick wall on the canvas using rectangles. Constants define the width and height of each brick, wh...

This is a Circle object on our canvas named ball. Point A is on the far left edge of the circle. How can we calculate the x-coordinate of point A?

ball.getX() - ball.getRadius();

Which statement should we use to determine if a ball is hitting the left edge of the window?

if(ball.getX() - ball.getRadius() <= 0){
//ball is hitting left edge
}

9.4.4: Hotspot Ball

This program creates a ball that continuously bounces around the canvas. The ball is initialized at a starting position ...

9.4.5: Trail

This program makes a ball bounce around the canvas while leaving a visible trail. The ball moves with set horizontal and...

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

9.3.5: Circle Wall

This program creates a wall of circles across the canvas. Constants define the circle radius and the drawing delay. Global variables track the current x and y positions and a counter for coloring. The start() function sets a timer to repeatedly call the draw() function. The draw() function creates a circle at the current position and colors every other circle red. After adding the circle, the x-position increases to place the next circle, and when it reaches the canvas width, x resets and y moves down. This continues until the y-position exceeds the canvas height, at which point the timer stops. The result is a neatly spaced wall of alternating red and default-colored circles.

9.3.6: Brick Wall

This program builds a brick wall on the canvas using rectangles. Constants define the width and height of each brick, while global variables track the current x and y positions and a counter. The start() function sets a fast timer to repeatedly call the draw() function. Each draw() call creates a rectangle at the current position with a random red color and adds it to the canvas. The x-position then moves right for the next brick, and if it exceeds the canvas width, x resets to 0 and y moves up for the next row. The process continues until the y-position moves beyond the top of the canvas, stopping the timer. The result is a stacked wall of red bricks covering the canvas.

This is a Circle object on our canvas named ball. Point A is on the far left edge of the circle. How can we calculate the x-coordinate of point A?

ball.getX() - ball.getRadius();

Which statement should we use to determine if a ball is hitting the left edge of the window?

if(ball.getX() - ball.getRadius() <= 0){
//ball is hitting left edge
}

9.4.4: Hotspot Ball

This program creates a ball that continuously bounces around the canvas. The ball is initialized at a starting position and moves with set horizontal and vertical speeds. The draw() function, called by a timer, updates the ball’s position and checks for collisions with the canvas walls. When the ball hits a wall, its direction reverses, making it bounce. Additionally, the switchColor() function changes the ball’s color based on its horizontal position: green if it is on the right half of the canvas and blue if on the left. This creates a dynamic bouncing effect with color changes as the ball moves.

9.4.5: Trail

This program makes a ball bounce around the canvas while leaving a visible trail. The ball moves with set horizontal and vertical speeds and bounces when it hits the walls. Each time the ball moves, a smaller cyan circle is drawn at its current position, creating a trail of its path. The checkWalls() function reverses the ball’s direction whenever it hits any edge of the canvas. A counter keeps track of how many times the ball has bounced, and when it reaches the maximum allowed bounces, the animation stops. This creates a visual effect of a moving ball tracing its path across the screen.

Suppose we've written a function drawCircle that we want to call every time the mouse is clicked. How can we do this?

mouseClickMethod(drawCircle);

What is a callback function?
A function passed to an event handler that is called every time a certain event happens.

9.5.5: Teleporting Ball

This program creates a ball that bounces around the canvas and can teleport to the mouse click position. The ball moves at set horizontal and vertical speeds, reversing direction whenever it hits a wall. When the user clicks the mouse, the teleport() function moves the ball to the click location and changes its color randomly. The checkWalls() function ensures the ball bounces off all edges of the canvas. The combination of bouncing and teleporting creates a dynamic and interactive animation where the ball continuously moves and responds to user input.

9.5.6: Pause

This program creates a ball that bounces around the canvas and can be paused or resumed with a mouse click. The ball moves at set speeds in both horizontal and vertical directions, reversing direction when it hits a wall. The paused variable keeps track of whether the ball should move. Clicking the mouse toggles the paused state using the pause() function. When paused is false, the draw() function moves the ball and checks for wall collisions. When paused is true, the ball stops moving, effectively freezing the animation. This allows interactive control over the bouncing ball’s motion.