8000 started HTML5 canvas work · wcski/JavaScript30@9c6a341 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c6a341

Browse files
author
RELIAS\wcoleman
committed
started HTML5 canvas work
1 parent d349c06 commit 9c6a341

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

08 - Fun with HTML5 Canvas/index-START.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@
77
<body>
88
<canvas id="draw" width="800" height="800"></canvas>
99
<script>
10+
const canvas = document.querySelector('#draw');
11+
const ctx = canvas.getContext('2d');
12+
canvas.width = window.innerWidth;
13+
canvas.height = window.innerHeight;
14+
ctx.strokeStyle='#BADA55';
15+
ctx.lineJoin = 'round';
16+
ctx.lineCap = 'round';
17+
18+
let isDrawing = false;
19+
let lastX = 0;
20+
let lastY = 0;
21+
22+
function draw(e){
23+
if(!isDrawing) return; // stop the function from running when they are not moused down
24+
console.log(e);
25+
};
26+
27+
canvas.addEventListener('mousemove', draw);
28+
canvas.addEventListener('mousedown', () => isDrawing = true);
29+
canvas.addEventListener('mouseup', () => isDrawing = false);
30+
canvas.addEventListener('mouseout', () => isDrawing = false);
1031
</script>
1132

1233
<style>

0 commit comments

Comments
 (0)
0