-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdessiner.html
More file actions
79 lines (76 loc) · 2.05 KB
/
dessiner.html
File metadata and controls
79 lines (76 loc) · 2.05 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dessin</title>
<style>
#canvas{
border: 2px solid;
background-image: url(png.png);
}
body{
margin: 0;
}
#lien{
text-decoration: none;
font-family: Arial, Helvetica, sans-serif;
color: black;
font-size: large;
padding: 10px;
background-color: rgb(89, 89, 255);
border-radius: 5px;
top: 10px;
position: relative;
transition: .3s;
margin-left: 5px;
}
#lien:focus{
outline: none;
}
#lien:hover{
background-color: rgb(22, 22, 145);
color: white;
}
</style>
<meta name="robots" content="none">
</head>
<body>
<canvas id="canvas" width="750" height="300" onmousemove="dessin()"></canvas><br>
<input type="color" name="" id="color">
<input type="range" min="2" max="50" value="30" id="taille"
><span id="nombre">30</span><br>
<a href="" id="lien" download="Image magnifique">Télécharger l'image</a>
<script>
canvas = document.getElementById('canvas');
ctx = canvas.getContext('2d');
var pressed = false;
canvas.addEventListener('mousedown', function(){
pressed = true;
})
canvas.addEventListener('mouseup', function(){
pressed = false;
})
document.getElementById('taille').oninput = function(){
document.getElementById('nombre').innerHTML = document.getElementById('taille').value;
}
function dessin(){
if(pressed == true){
ctx.fillStyle = document.getElementById('color').value;
var x = event.clientX;
var y = event.clientY;
var taille = document.getElementById('taille').value;
ctx.beginPath();
ctx.arc(x, y, taille, Math.PI * 2, false);
ctx.closePath();
ctx.fill();
}
}
function lien(){
document.getElementById('lien').href = canvas.toDataURL();
}
setInterval(lien, 1);
setInterval(dessin, 1);
</script>
</body>
</html>