forked from creativecoding2022/creativecoding2022.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
40 lines (29 loc) · 939 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const canvas = document.querySelector('#drawingCanvas');
const context = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// const background = new Image();
const img_mov = document.createElement('img');
const img_mov2 = document.createElement('img');
// background.src = './imagenes/page/logo.jpg';
img_mov.src = 'imagenes/img_mov/pincel_1.png';
img_mov2.src = 'imagenes/img_mov/pincel_2.png';
let pincel = img_mov;
// background.onload = () => {
// ctx.drawImage(background, 0, 0)
// }
const mouse_drawing = (evento) => {
const left = evento.clientX;
const top = evento.clientY;
context.drawImage(pincel, left, top);
}
const click_drawing = () => {
if (pincel === img_mov) {
pincel = img_mov2;
}
else {
pincel = img_mov;
}
}
canvas.addEventListener('click', click_drawing);
canvas.addEventListener('mousemove', mouse_drawing);