Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do all canvas examples use ctx?

Is this a requirement or a convention? If it's a convention what's the reason? Ctx doesn't seem especially memorable or intuitive.

e.g.

var ctx = document.getElementById('canvas').getContext('2d'); 
like image 434
j08691 Avatar asked Feb 14 '11 15:02

j08691


People also ask

What does CTX mean in canvas?

It is just name for variable. It could be anything. Ctx is just short word for ConTeXt.

What does CTX stand for in programming?

It typically stands for "context". Usually this is some structure that gets passed around to functions in a library, used to maintain state (i.e., the context of the function call).

What is the purpose of getContext ()?

getContext() method returns a drawing context on the canvas, or null if the context identifier is not supported, or the canvas has already been set to a different context mode.

What is canvas getContext (' 2D ')?

The CanvasRenderingContext2D interface, part of the Canvas API, provides the 2D rendering context for the drawing surface of a <canvas> element. It is used for drawing shapes, text, images, and other objects.


1 Answers

It is a shorthand for the word "context". That's it.

Of course you can use whatever name you like - there is no real naming convention in this instance.

like image 135
Jacob Relkin Avatar answered Sep 16 '22 15:09

Jacob Relkin