+ 1
var can = document.getElementById("canvas1"); var ctx = can.getContext("2d");
What is can what is ctx
2 Respostas
+ 2
can is shortcut for canvas it is their choice we can name it fan man lan anything. ctx is shortcut for context. if we don't name it we will have to write that document.get... Everytime in the code instead we write can. and use in drawing
+ 1
they are variables that you have just created and defined by using those 2 lines.
'var can' creates a variable (var) called 'can' which can then be used to assign some value to. In this particular case you assigned the HTML element 'canvas' to it by referencing to it through the 'document.getElementById' javascript code.
after that you can actually use the 'can' variable every time you refer to the HTML canvas element.
On initial definition you can call the variable whatever you like. 'can' or 'myCanvas' or 'whatever'.