+ 1

Var and ctx

Which language do these to belong..

26th Nov 2016, 11:29 AM
Alex King
Alex King - avatar
3 Answers
+ 5
ctx is just a variable name but mostly it is used when getting context for a canvas element in a html page: <canvas id="myCanvas" width="200" height="100"></canvas> and in the Javascript code: var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); the getContext("2d") method provides tools to draw 2 dimensional objects on the canvas. any actions like drawing line: ctx.moveTo(0,0); // start from point 0,0 ctx.lineTo(200,100); // draw a line from current location to (200, 100 ctx.stroke(); // draw the line notice that to draw on the canvas, we are using the ctx object to draw and not the canvas object.
26th Nov 2016, 12:28 PM
Burey
Burey - avatar
+ 2
var is of javascript and ctx of canvas js you were seeing canvas it is controlled by js codes ctx was general name any keyword can be used as Burey Said
26th Nov 2016, 11:36 AM
Sandeep Chatterjee
+ 1
K thanks
26th Nov 2016, 1:11 PM
Alex King
Alex King - avatar