Q1. HTML5 - Canvas (20 Points) Write the JavaScript code for drawing the following pattern of red and blue balls using H
Posted: Sun May 15, 2022 10:13 am
Q1. HTML5 - Canvas (20 Points) Write the JavaScript code for drawing the following pattern of red and blue balls using HTML5 canvas. The pattern starts at the bottom left of the canvas and goes all the way to the top of the canvas. The canvas's id attribute is testCanvas. The width and the height of the canvas are equal and is a multiple of the diameter of the ball. The code should work for any width (and equal height) specified in the corresponding html. Do not hard code the width or the height in the JavaScript. You can assume that the radius of the ball is 15 units. Hint: Calculate the number of rows and draw the pattern using a nested loop. In the sample shown, there are 10 rows for a width and height of 300 units. You can assume that the canvas has a border.