+ 1

Why this lines? Can anyone one explain each code and its work?

var c=document.getElementById("canvas1"); var ctx=c.getContext("2d"); ctx.fillRect(20,20,100,100);

27th Dec 2017, 4:03 AM
Nisha Samuel Paul AJ
Nisha Samuel Paul AJ - avatar
3 Respuestas
+ 3
var c = document.getElementById("canvas1"); this gets your html canvas element(by its id which is canvas1), and stores it in the var c. var ctx = c.getContext("2d"); this creates your drawing context of the canvas ctx.fillRect(20,20,100,100); this draws a rectangle in your canvas context, at the position (x)20, (y)20, size of (width)100,(height)100
27th Dec 2017, 4:08 AM
Welliton Malta
Welliton Malta - avatar
+ 1
wow.! thank you buddy
27th Dec 2017, 4:09 AM
Nisha Samuel Paul AJ
Nisha Samuel Paul AJ - avatar
+ 1
you're welcome :)
27th Dec 2017, 4:12 AM
Welliton Malta
Welliton Malta - avatar