MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / draw

Function draw

assets/js/etch_sketch.js:28–53  ·  view source on GitHub ↗
({ key })

Source from the content-addressed store, hash-verified

26let color = 0;
27//write a draw function
28function draw({ key }) {
29 console.log(key);
30 //begin path
31 ctx.beginPath();
32 ctx.moveTo(w, h);
33 //move the value depending on what user did
34 switch (key) {
35 case "ArrowUp":
36 h = h - MOVE_AMOUNT;
37 break;
38 case "ArrowDown":
39 h = h + MOVE_AMOUNT;
40 break;
41 case "ArrowLeft":
42 w = w - MOVE_AMOUNT;
43 break;
44 case "ArrowRight":
45 w = w + MOVE_AMOUNT;
46 break;
47 }
48
49 ctx.lineTo(w, h);
50 color = color + Math.random() * 10;
51 ctx.strokeStyle = `hsl(${color},100%,50%)`;
52 ctx.stroke();
53}
54//handler for keys
55function handleKeys(e) {
56 if (e.key.includes("Arrow")) {

Callers 1

handleKeysFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected