Question
Draw a brick wall that covers the canvas, brick by brick, starting from the bottom left corner. One brick should be drawn every 50ms through
Draw a brick wall that covers the canvas, brick by brick, starting from the bottom left corner. One brick should be drawn every 50ms through a function named drawBrick(), which takes in the parameters of width, height, x-position, and y-position, in that order. Your code should work for any brick height and length values.
I am getting the following error. Can you please help?
TypeError: Invalid value for `width`. Make sure you are passing finite numbers to `new Rectangle(width, height)`. Did you forget the parentheses in `getWidth()` or `getHeight()`? Or did you perform a calculation on a variable that is not a number? at 87:13
HERE IS MY CODE:
const BRICK_WIDTH = 50; const BRICK_HEIGHT = 20; const CANVAS_WIDTH = getWidth(); const CANVAS_HEIGHT = getHeight(); let xPos = 0; let yPos = CANVAS_HEIGHT - BRICK_HEIGHT; let brick; function main() {
brick = drawBrick(BRICK_WIDTH, BRICK_HEIGHT, xPos, yPos); setTimer(drawBrick,50); }
function drawBrick(width, height, xPos, yPos) { brick = new Rectangle(width, height); brick.setColor(Color.randomRed()); brick.setPosition(xPos, yPos); add(brick); xPos = xPos + width; if (xPos > CANVAS_WIDTH) { xPos = 0; yPos = yPos - height; } if (yPos == 0 && xPos > CANVAS_WIDTH) { stopTimer(drawBrick); } return brick; }
main();
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started