MCPcopy Create free account
hub / github.com/AyushSaini00/60minuteJavaScript / getCanvas

Function getCanvas

HTML-Canvas/app.js:5–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3const rangeElement = document.getElementById('range');
4
5function getCanvas(){
6
7 if(canvas.getContext){
8 //ctx object will provide the drawing interface
9 const ctx = canvas.getContext('2d');
10
11 //resize the canvas according to dimensions of window
12 // resizing();
13
14 //flag variable
15 let painting = false;
16
17 function startDrawing(event){
18 painting = true;
19 draw(event);
20 }
21
22 function stopDrawing(){
23 painting = false;
24 ctx.beginPath();
25 }
26
27 function draw(event){
28 //if not painting , then return
29 if(!painting) return;
30
31 ctx.lineWidth = rangeElement.value;
32 ctx.lineCap = 'round';
33 ctx.strokeStyle = colorElement.value;
34
35 ctx.lineTo(event.clientX, event.clientY);
36 ctx.stroke();
37
38 ctx.beginPath();
39 ctx.moveTo(event.clientX, event.clientY);
40 }
41
42 window.addEventListener('mousedown', startDrawing);
43 window.addEventListener('mouseup', stopDrawing);
44 window.addEventListener('mousemove', draw);
45 } else {
46 console.log(`brower doesn't support canvas`);
47 }
48}
49
50window.addEventListener('load', getCanvas);
51

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected