-
Notifications
You must be signed in to change notification settings - Fork 0
/
slider.js
45 lines (35 loc) · 926 Bytes
/
slider.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
41
42
43
44
45
function Slider(y_line, span, thickness){
this.y_line = y_line;
this.span = span;
this.thickness = thickness;
var value = 0;
var topLeft = [-1, -1];
var isDragging = false;
this.draw = function(){
if(isDragging){
value = (mouseX - topLeft[0]) / span;
if(value > 1) value = 1;
if(value < 0) value = 0;
}
colorMode(HSB);
fill(value * 360, 100, 100);
topLeft = [width/2 - span/2, y_line - thickness/2];
rect(topLeft[0], topLeft[1], span, thickness);
colorMode(RGB);
fill(255);
circle(topLeft[0] + thickness/2 + (value * (span - thickness)), topLeft[1] + thickness/2, thickness);
}
this.onClickStart = function(){
if((mouseX > topLeft[0]) && (mouseY > topLeft[1])){
if((mouseX < topLeft[0] + span) && (mouseY < topLeft[1] + thickness)){
isDragging = true;
}
}
}
this.onClickEnd = function(){
isDragging = false;
}
this.getValue = function(){
return value;
}
}