<aside> 💡 Take the 1st pose picture once countdown1 is over
</aside>
Global variable image1 which will refer to our 1st pose picture
let canvas = document.getElementById('canvas');
var context1 = canvas.getContext('2d');
let image1;
function picture1() {
image1 = context.drawImage(video, 0, 0, 500, 500);
countdown2();
}
function picture1()
is called from within function countdown1()
once the countdown is over
In this function we want to take a picture of the user once the countdown is over i.e reaches 0
The <canvas>
element is a container whichwill display images that are drawn into it
"The getContext() method returns an object that provides methods and properties for drawing on the canvas." (W3 schools)
So we use the getContext()
method of canvas to get a 2d context, since we want to take a picture which is 2D (flat). And the reference to the object returned by getContext() is the variable context1
Then we draw the current video frame at the moment the countdown stops (at 0) by using the drawImage()
image method of the context object (referenced by let context1
)
The drawImage() method takes 5 parameters:
Syntax: context.drawImage(img,x,y,width,height);