Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions

Question

internationalization of business?

Answered: 1 week ago