-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·122 lines (109 loc) · 2.21 KB
/
index.html
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>canvas - pixels finger</title>
<style>
html,
body {
height: 100%;
}
body {
margin: 0;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
background-color: #222;
font: 16px sans-serif;
color: #ddd;
}
canvas {
border-radius: 8px;
margin-bottom: 32px;
transition: .5s box-shadow;
}
canvas:hover {
box-shadow: 0 0px 20px 8px rgba( 0, 0, 0, .2 );
}
div {
display: flex;
align-items: center;
opacity: .2;
transition: .7s opacity;
}
canvas:not(:hover) ~ div {
opacity: 1;
}
</style>
</head>
<body>
<canvas></canvas>
<div>
<span>radius</span>
<input type="range" id="radius" min="2" max="100" step="1"/>
</div>
<div>
<span>intensity</span>
<input type="range" id="intensity" min=".1" max="1" step=".01"/>
</div>
<div>
<button id="reset">reset</button>
</div>
<script src="image-test.js"></script>
<script src="canvas-pixelsfinger.js"></script>
<script>
const canvas = document.querySelector( "canvas" ),
inpIntensity = document.querySelector( "#intensity" ),
inpRadius = document.querySelector( "#radius" ),
inpReset = document.querySelector( "#reset" ),
ctx = canvas.getContext( "2d" ),
img = document.createElement( "img" );
let cnvX,
cnvY,
prvX,
prvY,
radius = 20,
intensity = .5,
fingerdown = false;
img.onload = () => {
canvas.width = img.width;
canvas.height = img.height;
inpReset.onclick();
window.onresize();
};
window.onresize = () => {
const bcr = canvas.getBoundingClientRect();
cnvX = bcr.left;
cnvY = bcr.top;
};
inpRadius.value = radius;
inpIntensity.value = intensity;
inpRadius.onchange = () => radius = "" + inpRadius.value;
inpIntensity.onchange = () => intensity = "" + inpIntensity.value;
inpReset.onclick = () => {
ctx.fillStyle = "#333";
ctx.fillRect( 0, 0, img.width, img.height );
ctx.drawImage( img, 0, 0 );
};
canvas.onmousedown = e => {
fingerdown = true;
prvX = e.pageX - cnvX;
prvY = e.pageY - cnvY;
};
document.onmouseup = () => {
fingerdown = false;
};
document.onmousemove = e => {
if ( fingerdown ) {
const x = e.pageX - cnvX,
y = e.pageY - cnvY;
pixelsFinger( ctx, radius, prvX, prvY, x, y, intensity );
prvX = x;
prvY = y;
}
};
img.src = IMAGE;
</script>
</body>
</html>