uil 1.0.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -0
- package/build/uil.js +7040 -4199
- package/build/uil.min.js +6 -4
- package/build/uil.module.js +7200 -2761
- package/examples/js/BufferGeometryUtils.js +921 -0
- package/examples/js/SimplexNoise.js +324 -0
- package/examples/js/controls/OrbitControls.js +1215 -0
- package/examples/js/controls/OrbitControls_.js +1042 -0
- package/examples/js/libs/sea3d.min.js +373 -0
- package/examples/js/libs/three.min.js +6 -0
- package/examples/js/math.js +447 -0
- package/examples/js/objects/Landscape.js +778 -0
- package/examples/js/objects/Lensflare.js +372 -0
- package/examples/js/objects/SuperSky.js +297 -0
- package/examples/js/objects/Water.js +329 -0
- package/package.json +56 -54
- package/src/Uil.js +2 -17
- package/src/Uil_dev.js +15 -0
- package/src/core/Gui.js +601 -299
- package/src/core/Proto.js +490 -220
- package/src/core/Roots.js +864 -0
- package/src/core/Tools.js +591 -140
- package/src/core/V2.js +131 -0
- package/src/core/add.js +52 -57
- package/src/proto/Bool.js +117 -52
- package/src/proto/Button.js +286 -146
- package/src/proto/Circular.js +162 -130
- package/src/proto/Color.js +331 -289
- package/src/proto/Empty.js +15 -0
- package/src/proto/Fps.js +232 -159
- package/src/proto/Graph.js +310 -0
- package/src/proto/Grid.js +297 -0
- package/src/proto/Group.js +334 -160
- package/src/proto/Item.js +120 -0
- package/src/proto/Joystick.js +159 -185
- package/src/proto/Knob.js +210 -91
- package/src/proto/List.js +661 -249
- package/src/proto/Numeric.js +329 -162
- package/src/proto/Pad2D.js +268 -0
- package/src/proto/Rubric.js +0 -0
- package/src/proto/Select.js +178 -0
- package/src/proto/Selector.js +13 -0
- package/src/proto/Slide.js +191 -185
- package/src/proto/TextInput.js +149 -59
- package/src/proto/Title.js +40 -31
package/src/proto/Color.js
CHANGED
|
@@ -1,369 +1,411 @@
|
|
|
1
|
-
import { Tools } from '../core/Tools';
|
|
2
|
-
import { Proto } from '../core/Proto';
|
|
1
|
+
import { Tools } from '../core/Tools.js';
|
|
2
|
+
import { Proto } from '../core/Proto.js';
|
|
3
|
+
import { V2 } from '../core/V2.js';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Proto.call( this, o );
|
|
5
|
+
export class Color extends Proto {
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
constructor( o = {} ) {
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
this.ww = this.sb;
|
|
12
|
-
this.oldWidth = 0;
|
|
9
|
+
super( o );
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
this.side = o.side || 'down';
|
|
16
|
-
this.holdTop = 0;
|
|
17
|
-
|
|
18
|
-
this.wheelWidth = this.ww*0.1;
|
|
19
|
-
this.decal = this.h + 2;
|
|
20
|
-
|
|
21
|
-
this.radius = (this.ww - this.wheelWidth) * 0.5 - 1;
|
|
22
|
-
this.square = Math.floor((this.radius - this.wheelWidth * 0.5) * 0.7) - 1;
|
|
23
|
-
this.mid = Math.floor(this.ww * 0.5 );
|
|
24
|
-
this.markerSize = this.wheelWidth * 0.3;
|
|
11
|
+
//this.autoHeight = true;
|
|
25
12
|
|
|
26
|
-
|
|
13
|
+
this.ctype = o.ctype || 'hex';
|
|
27
14
|
|
|
28
|
-
|
|
15
|
+
this.wfixe = 256;
|
|
29
16
|
|
|
30
|
-
|
|
17
|
+
this.cw = this.sb > 256 ? 256 : this.sb;
|
|
18
|
+
if(o.cw != undefined ) this.cw = o.cw;
|
|
31
19
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
// color up or down
|
|
21
|
+
this.side = o.side || 'down';
|
|
22
|
+
this.up = this.side === 'down' ? 0 : 1;
|
|
23
|
+
|
|
24
|
+
this.baseH = this.h;
|
|
37
25
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
this.offset = new V2();
|
|
27
|
+
this.decal = new V2();
|
|
28
|
+
this.pp = new V2();
|
|
41
29
|
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
this.c[2] = this.dom( 'div', this.css.txt + 'height:'+(this.h-4)+'px;' + 'border-radius:'+this.radius+'px; line-height:'+(this.h-8)+'px;' );
|
|
31
|
+
this.s[2] = this.c[2].style;
|
|
44
32
|
|
|
45
|
-
|
|
33
|
+
this.s[2].textShadow = 'none'
|
|
46
34
|
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
if( this.up ){
|
|
36
|
+
this.s[2].top = 'auto';
|
|
37
|
+
this.s[2].bottom = '2px';
|
|
38
|
+
}
|
|
49
39
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.ctxMask.translate(this.mid, this.mid);
|
|
53
|
-
this.ctxOverlay.translate(this.mid, this.mid);
|
|
40
|
+
//this.c[0].style.textAlign = 'center';
|
|
41
|
+
//this.c[0].style.flex = '1 0 auto'
|
|
54
42
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
43
|
+
this.c[3] = this.getColorRing();
|
|
44
|
+
this.c[3].style.visibility = 'hidden';
|
|
45
|
+
|
|
46
|
+
this.hsl = null;
|
|
47
|
+
this.value = '#ffffff';
|
|
48
|
+
if( o.value !== undefined ){
|
|
49
|
+
if( o.value instanceof Array ) this.value = Tools.rgbToHex( o.value );
|
|
50
|
+
else if(!isNaN(o.value)) this.value = Tools.hexToHtml( o.value );
|
|
51
|
+
else this.value = o.value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.bcolor = null;
|
|
55
|
+
this.isDown = false;
|
|
56
|
+
this.fistDown = false;
|
|
57
|
+
|
|
58
|
+
this.notext = o.notext || false
|
|
59
|
+
|
|
60
|
+
this.tr = 98;
|
|
61
|
+
this.tsl = Math.sqrt(3) * this.tr;
|
|
62
|
+
|
|
63
|
+
this.hue = 0;
|
|
64
|
+
this.d = 256;
|
|
65
|
+
|
|
66
|
+
this.setColor( this.value );
|
|
67
|
+
|
|
68
|
+
this.init();
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
this.c[5].events = [ 'mousedown', 'mousemove', 'mouseup', 'mouseout' ];
|
|
70
|
+
if( o.open !== undefined ) this.open();
|
|
68
71
|
|
|
69
|
-
|
|
72
|
+
}
|
|
70
73
|
|
|
71
|
-
|
|
74
|
+
testZone ( mx, my ) {
|
|
72
75
|
|
|
73
|
-
|
|
76
|
+
let l = this.local;
|
|
77
|
+
if( l.x === -1 && l.y === -1 ) return '';
|
|
74
78
|
|
|
75
|
-
Color.prototype = Object.create( Proto.prototype );
|
|
76
|
-
Color.prototype.constructor = Color;
|
|
77
79
|
|
|
78
|
-
Color.prototype.handleEvent = function( e ) {
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
if( this.up && this.isOpen ){
|
|
82
|
+
|
|
83
|
+
if( l.y > this.wfixe ) return 'title';
|
|
84
|
+
else return 'color';
|
|
85
|
+
|
|
86
|
+
} else {
|
|
87
|
+
|
|
88
|
+
if( l.y < this.baseH+2 ) return 'title';
|
|
89
|
+
else if( this.isOpen ) return 'color';
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
}
|
|
82
93
|
|
|
83
|
-
switch( e.type ) {
|
|
84
|
-
case 'click': this.click(e); break;
|
|
85
|
-
case 'mousedown': this.down(e); break;
|
|
86
|
-
case 'mousemove': this.move(e); break;
|
|
87
|
-
case 'mouseup': this.up(e); break;
|
|
88
|
-
case 'mouseout': this.out(e); break;
|
|
89
94
|
}
|
|
90
95
|
|
|
91
|
-
|
|
96
|
+
// ----------------------
|
|
97
|
+
// EVENTS
|
|
98
|
+
// ----------------------
|
|
92
99
|
|
|
93
|
-
|
|
100
|
+
mouseup ( e ) {
|
|
94
101
|
|
|
95
|
-
|
|
102
|
+
this.isDown = false;
|
|
103
|
+
this.d = 256;
|
|
96
104
|
|
|
97
|
-
|
|
98
|
-
else this.hide();
|
|
105
|
+
}
|
|
99
106
|
|
|
100
|
-
|
|
107
|
+
mousedown ( e ) {
|
|
101
108
|
|
|
102
|
-
Color.prototype.up = function( e ){
|
|
103
109
|
|
|
104
|
-
|
|
110
|
+
let name = this.testZone( e.clientX, e.clientY );
|
|
105
111
|
|
|
106
|
-
};
|
|
107
112
|
|
|
108
|
-
|
|
113
|
+
//if( !name ) return;
|
|
114
|
+
if(name === 'title'){
|
|
115
|
+
if( !this.isOpen ) this.open();
|
|
116
|
+
else this.close();
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
109
119
|
|
|
110
|
-
this.hide();
|
|
111
120
|
|
|
112
|
-
|
|
121
|
+
if( name === 'color' ){
|
|
113
122
|
|
|
114
|
-
|
|
123
|
+
this.isDown = true;
|
|
124
|
+
this.fistDown = true
|
|
125
|
+
this.mousemove( e );
|
|
126
|
+
}
|
|
127
|
+
}
|
|
115
128
|
|
|
116
|
-
|
|
117
|
-
this.isDown = true;
|
|
118
|
-
this.move( e );
|
|
119
|
-
return false;
|
|
129
|
+
mousemove ( e ) {
|
|
120
130
|
|
|
121
|
-
|
|
131
|
+
let name = this.testZone( e.clientX, e.clientY );
|
|
122
132
|
|
|
123
|
-
|
|
133
|
+
let off, d, hue, sat, lum, rad, x, y, rr, T = Tools;
|
|
124
134
|
|
|
125
|
-
|
|
135
|
+
if( name === 'title' ) this.cursor('pointer');
|
|
126
136
|
|
|
127
|
-
|
|
128
|
-
var pos = { x: e.pageX - this.offset.left - this.mid, y: e.pageY - this.offset.top - this.mid };
|
|
129
|
-
this.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) > (this.square + 2);
|
|
137
|
+
if( name === 'color' ){
|
|
130
138
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
+
off = this.offset;
|
|
140
|
+
off.x = e.clientX - ( this.zone.x + this.decal.x + this.mid );
|
|
141
|
+
off.y = e.clientY - ( this.zone.y + this.decal.y + this.mid );
|
|
142
|
+
d = off.length() * this.ratio;
|
|
143
|
+
rr = off.angle();
|
|
144
|
+
if(rr < 0) rr += 2 * T.PI;
|
|
145
|
+
|
|
139
146
|
|
|
140
|
-
|
|
147
|
+
if ( d < 128 ) this.cursor('crosshair');
|
|
148
|
+
else if( !this.isDown ) this.cursor()
|
|
141
149
|
|
|
150
|
+
if( this.isDown ){
|
|
142
151
|
|
|
143
|
-
|
|
152
|
+
if( this.fistDown ){
|
|
153
|
+
this.d = d;
|
|
154
|
+
this.fistDown = false;
|
|
155
|
+
}
|
|
144
156
|
|
|
145
|
-
|
|
157
|
+
if ( this.d < 128 ) {
|
|
146
158
|
|
|
147
|
-
|
|
148
|
-
this.drawCircle();
|
|
149
|
-
this.drawMask();
|
|
150
|
-
this.drawMarkers();
|
|
159
|
+
if ( this.d > this.tr ) { // outside hue
|
|
151
160
|
|
|
152
|
-
|
|
161
|
+
hue = ( rr + T.pi90 ) / T.TwoPI;
|
|
162
|
+
this.hue = (hue + 1) % 1;
|
|
163
|
+
this.setHSL([(hue + 1) % 1, this.hsl[1], this.hsl[2]]);
|
|
153
164
|
|
|
154
|
-
|
|
165
|
+
} else { // triangle
|
|
155
166
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
this.h = this.ww + this.baseH + 10;
|
|
159
|
-
this.s[0].height = this.h+'px';
|
|
167
|
+
x = off.x * this.ratio;
|
|
168
|
+
y = off.y * this.ratio;
|
|
160
169
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if(!isNaN(this.holdTop)) this.s[0].top = (this.holdTop-(this.h-20))+'px';
|
|
164
|
-
setTimeout(function(){this.s[5].pointerEvents = 'auto';}.bind(this), 100);
|
|
165
|
-
}
|
|
170
|
+
let rr = (this.hue * T.TwoPI) + T.PI;
|
|
171
|
+
if(rr < 0) rr += 2 * T.PI;
|
|
166
172
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
173
|
+
rad = Math.atan2(-y, x);
|
|
174
|
+
if(rad < 0) rad += 2 * T.PI;
|
|
175
|
+
|
|
176
|
+
let rad0 = ( rad + T.pi90 + T.TwoPI + rr ) % (T.TwoPI),
|
|
177
|
+
rad1 = rad0 % ((2/3) * T.PI) - (T.pi60),
|
|
178
|
+
a = 0.5 * this.tr,
|
|
179
|
+
b = Math.tan(rad1) * a,
|
|
180
|
+
r = Math.sqrt(x*x + y*y),
|
|
181
|
+
maxR = Math.sqrt(a*a + b*b);
|
|
170
182
|
|
|
171
|
-
|
|
172
|
-
|
|
183
|
+
if( r > maxR ) {
|
|
184
|
+
let dx = Math.tan(rad1) * r;
|
|
185
|
+
let rad2 = Math.atan(dx / maxR);
|
|
186
|
+
if(rad2 > T.pi60) rad2 = T.pi60;
|
|
187
|
+
else if( rad2 < -T.pi60 ) rad2 = -T.pi60;
|
|
188
|
+
|
|
189
|
+
rad += rad2 - rad1;
|
|
173
190
|
|
|
174
|
-
|
|
191
|
+
rad0 = (rad + T.pi90 + T.TwoPI + rr) % (T.TwoPI),
|
|
192
|
+
rad1 = rad0 % ((2/3) * T.PI) - (T.pi60);
|
|
193
|
+
b = Math.tan(rad1) * a;
|
|
194
|
+
r = maxR = Math.sqrt(a*a + b*b);
|
|
195
|
+
}
|
|
175
196
|
|
|
176
|
-
|
|
197
|
+
lum = ((Math.sin(rad0) * r) / this.tsl) + 0.5;
|
|
198
|
+
|
|
199
|
+
let w = 1 - (Math.abs(lum - 0.5) * 2);
|
|
200
|
+
sat = (((Math.cos(rad0) * r) + (this.tr / 2)) / (1.5 * this.tr)) / w;
|
|
201
|
+
sat = T.clamp( sat, 0, 1 );
|
|
202
|
+
|
|
203
|
+
this.setHSL([this.hsl[0], sat, lum]);
|
|
177
204
|
|
|
178
|
-
|
|
179
|
-
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
180
209
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ----------------------
|
|
213
|
+
|
|
214
|
+
setHeight () {
|
|
215
|
+
|
|
216
|
+
this.h = this.isOpen ? this.wfixe + this.baseH + 5 : this.baseH;
|
|
217
|
+
this.s[0].height = this.h + 'px';
|
|
218
|
+
this.zone.h = this.h;
|
|
219
|
+
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
parentHeight ( t ) {
|
|
223
|
+
|
|
224
|
+
if ( this.group !== null ) this.group.calc( t );
|
|
225
|
+
else if ( this.isUI ) this.main.calc( t );
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
open () {
|
|
230
|
+
|
|
231
|
+
super.open();
|
|
232
|
+
|
|
233
|
+
this.setHeight();
|
|
234
|
+
|
|
235
|
+
if( this.up ) this.zone.y -= this.wfixe + 5;
|
|
236
|
+
|
|
237
|
+
let t = this.h - this.baseH;
|
|
238
|
+
|
|
239
|
+
this.s[3].visibility = 'visible';
|
|
240
|
+
//this.s[3].display = 'block';
|
|
241
|
+
this.parentHeight( t );
|
|
242
|
+
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
close () {
|
|
246
|
+
|
|
247
|
+
super.close();
|
|
248
|
+
|
|
249
|
+
if( this.up ) this.zone.y += this.wfixe + 5;
|
|
250
|
+
|
|
251
|
+
let t = this.h - this.baseH;
|
|
193
252
|
|
|
194
|
-
|
|
253
|
+
this.setHeight();
|
|
195
254
|
|
|
196
|
-
|
|
255
|
+
this.s[3].visibility = 'hidden';
|
|
256
|
+
//this.s[3].display = 'none';
|
|
257
|
+
this.parentHeight( -t );
|
|
197
258
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
this.value = this.bcolor;
|
|
259
|
+
}
|
|
201
260
|
|
|
202
|
-
|
|
203
|
-
this.c[2].textContent = Tools.htmlToHex( this.bcolor );
|
|
261
|
+
update ( up ) {
|
|
204
262
|
|
|
205
|
-
|
|
206
|
-
this.s[2].color = this.invert ? '#fff' : '#000';
|
|
263
|
+
let cc = Tools.rgbToHex( Tools.hslToRgb([ this.hsl[0], 1, 0.5 ]) );
|
|
207
264
|
|
|
208
|
-
|
|
265
|
+
this.moveMarkers();
|
|
266
|
+
|
|
267
|
+
this.value = this.bcolor;
|
|
209
268
|
|
|
210
|
-
|
|
211
|
-
if( this.ctype === 'rgb' ) this.send( Tools.htmlRgb( this.rgb ) );
|
|
212
|
-
if( this.ctype === 'hex' ) this.send( Tools.htmlToHex( this.value ) );
|
|
213
|
-
if( this.ctype === 'html' ) this.send();
|
|
269
|
+
this.setSvg( this.c[3], 'fill', cc, 2, 0 );
|
|
214
270
|
|
|
215
|
-
};
|
|
216
271
|
|
|
217
|
-
|
|
272
|
+
this.s[2].background = this.bcolor;
|
|
273
|
+
if(!this.notext) this.c[2].textContent = Tools.htmlToHex( this.bcolor );
|
|
218
274
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
275
|
+
this.invert = Tools.findDeepInver( this.rgb );
|
|
276
|
+
this.s[2].color = this.invert ? '#fff' : '#000';
|
|
277
|
+
|
|
278
|
+
if(!up) return;
|
|
279
|
+
|
|
280
|
+
if( this.ctype === 'array' ) this.send( this.rgb );
|
|
281
|
+
if( this.ctype === 'rgb' ) this.send( Tools.htmlRgb( this.rgb ) );
|
|
282
|
+
if( this.ctype === 'hex' ) this.send( Tools.htmlToHex( this.value ) );
|
|
283
|
+
if( this.ctype === 'html' ) this.send();
|
|
284
|
+
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
setValue ( v ){
|
|
288
|
+
|
|
289
|
+
if( v instanceof Array ) this.value = Tools.rgbToHex( v );
|
|
290
|
+
else if(!isNaN(v)) this.value = Tools.hexToHtml( v );
|
|
291
|
+
else this.value = v;
|
|
292
|
+
|
|
293
|
+
this.setColor( this.value )
|
|
224
294
|
this.update();
|
|
225
|
-
}
|
|
226
|
-
return this;
|
|
227
|
-
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
Color.prototype.setHSL = function( hsl ){
|
|
231
|
-
|
|
232
|
-
this.hsl = hsl;
|
|
233
|
-
this.rgb = Tools.hslToRgb( hsl );
|
|
234
|
-
this.bcolor = Tools.rgbToHex( this.rgb );
|
|
235
|
-
this.update( true );
|
|
236
|
-
return this;
|
|
237
|
-
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
Color.prototype.calculateMask = function(sizex, sizey, outputPixel){
|
|
241
|
-
var isx = 1 / sizex, isy = 1 / sizey;
|
|
242
|
-
for (var y = 0; y <= sizey; ++y) {
|
|
243
|
-
var l = 1 - y * isy;
|
|
244
|
-
for (var x = 0; x <= sizex; ++x) {
|
|
245
|
-
var s = 1 - x * isx;
|
|
246
|
-
var a = 1 - 2 * Math.min(l * s, (1 - l) * s);
|
|
247
|
-
var c = (a > 0) ? ((2 * l - 1 + a) * .5 / a) : 0;
|
|
248
|
-
outputPixel(x, y, c, a);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
Color.prototype.drawMask = function(){
|
|
254
|
-
var size = this.square * 2, sq = this.square;
|
|
255
|
-
var sz = Math.floor(size / 2);
|
|
256
|
-
var buffer = document.createElement('canvas');
|
|
257
|
-
buffer.width = buffer.height = sz + 1;
|
|
258
|
-
var ctx = buffer.getContext('2d');
|
|
259
|
-
var frame = ctx.getImageData(0, 0, sz + 1, sz + 1);
|
|
260
|
-
|
|
261
|
-
var i = 0;
|
|
262
|
-
this.calculateMask(sz, sz, function (x, y, c, a) {
|
|
263
|
-
frame.data[i++] = frame.data[i++] = frame.data[i++] = c * 255;
|
|
264
|
-
frame.data[i++] = a * 255;
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
ctx.putImageData(frame, 0, 0);
|
|
268
|
-
this.ctxMask.drawImage(buffer, 0, 0, sz + 1, sz + 1, -sq, -sq, sq * 2, sq * 2);
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
Color.prototype.drawCircle = function(){
|
|
272
|
-
var n = 24,r = this.radius, w = this.wheelWidth, nudge = 8 / r / n * Math.PI, m = this.ctxMask, a1 = 0, color1, d1;
|
|
273
|
-
var ym, am, tan, xm, color2, d2, a2, ar;
|
|
274
|
-
m.save();
|
|
275
|
-
m.lineWidth = w / r;
|
|
276
|
-
m.scale(r, r);
|
|
277
|
-
for (var i = 0; i <= n; ++i) {
|
|
278
|
-
d2 = i / n;
|
|
279
|
-
a2 = d2 * Math.PI * 2;
|
|
280
|
-
ar = [Math.sin(a1), -Math.cos(a1), Math.sin(a2), -Math.cos(a2)];
|
|
281
|
-
am = (a1 + a2) * 0.5;
|
|
282
|
-
tan = 1 / Math.cos((a2 - a1) * 0.5);
|
|
283
|
-
xm = Math.sin(am) * tan, ym = -Math.cos(am) * tan;
|
|
284
|
-
color2 = Tools.rgbToHex( Tools.hslToRgb([d2, 1, 0.5]) );
|
|
285
|
-
if (i > 0) {
|
|
286
|
-
var grad = m.createLinearGradient(ar[0], ar[1], ar[2], ar[3]);
|
|
287
|
-
grad.addColorStop(0, color1);
|
|
288
|
-
grad.addColorStop(1, color2);
|
|
289
|
-
m.strokeStyle = grad;
|
|
290
|
-
m.beginPath();
|
|
291
|
-
m.moveTo(ar[0], ar[1]);
|
|
292
|
-
m.quadraticCurveTo(xm, ym, ar[2], ar[3]);
|
|
293
|
-
m.stroke();
|
|
294
|
-
}
|
|
295
|
-
a1 = a2 - nudge;
|
|
296
|
-
color1 = color2;
|
|
297
|
-
d1 = d2;
|
|
298
|
-
}
|
|
299
|
-
m.restore();
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
Color.prototype.drawMarkers = function(){
|
|
303
|
-
|
|
304
|
-
var m = this.markerSize, ra=this.radius, sz = this.ww, lw = Math.ceil(m/ 4), r = m - lw + 1, c1 = this.invert ? '#fff' : '#000', c2 = this.invert ? '#000' : '#fff';
|
|
305
|
-
var angle = this.hsl[0] * 6.28;
|
|
306
|
-
var ar = [Math.sin(angle) * ra, -Math.cos(angle) * ra, 2 * this.square * (.5 - this.hsl[1]), 2 * this.square * (.5 - this.hsl[2]) ];
|
|
307
|
-
|
|
308
|
-
var circles = [
|
|
309
|
-
{ x: ar[2], y: ar[3], r: m, c: c1, lw: lw },
|
|
310
|
-
{ x: ar[2], y: ar[3], r: r, c: c2, lw: lw + 1 },
|
|
311
|
-
{ x: ar[0], y: ar[1], r: m, c: '#fff', lw: lw },
|
|
312
|
-
{ x: ar[0], y: ar[1], r: r, c: '#000', lw: lw + 1 },
|
|
313
|
-
];
|
|
314
|
-
this.ctxOverlay.clearRect(-this.mid, -this.mid, sz, sz);
|
|
315
|
-
var i = circles.length;
|
|
316
|
-
while(i--){
|
|
317
|
-
var c = circles[i];
|
|
318
|
-
this.ctxOverlay.lineWidth = c.lw;
|
|
319
|
-
this.ctxOverlay.strokeStyle = c.c;
|
|
320
|
-
this.ctxOverlay.beginPath();
|
|
321
|
-
this.ctxOverlay.arc(c.x, c.y, c.r, 0, Math.PI * 2, true);
|
|
322
|
-
this.ctxOverlay.stroke();
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
295
|
|
|
326
|
-
|
|
296
|
+
}
|
|
327
297
|
|
|
328
|
-
|
|
298
|
+
setColor ( color ) {
|
|
329
299
|
|
|
330
|
-
|
|
331
|
-
|
|
300
|
+
let unpack = Tools.unpack(color);
|
|
301
|
+
if (this.bcolor !== color && unpack) {
|
|
332
302
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
this.mid = Math.floor(this.ww * 0.5 );
|
|
337
|
-
this.markerSize = this.wheelWidth * 0.3;
|
|
303
|
+
this.bcolor = color;
|
|
304
|
+
this.rgb = unpack;
|
|
305
|
+
this.hsl = Tools.rgbToHsl( this.rgb );
|
|
338
306
|
|
|
339
|
-
|
|
307
|
+
this.hue = this.hsl[0];
|
|
340
308
|
|
|
341
|
-
|
|
342
|
-
|
|
309
|
+
this.update();
|
|
310
|
+
}
|
|
311
|
+
return this;
|
|
343
312
|
|
|
344
|
-
|
|
345
|
-
s[3].height = (this.square * 2 - 1) + 'px';
|
|
346
|
-
s[3].top = (this.mid+this.decal )-this.square + 'px';
|
|
347
|
-
s[3].left = (this.mid+this.sa )-this.square + 'px';
|
|
313
|
+
}
|
|
348
314
|
|
|
349
|
-
|
|
350
|
-
s[4].left = this.sa + 'px';
|
|
351
|
-
s[4].top = this.decal + 'px';
|
|
315
|
+
setHSL ( hsl ) {
|
|
352
316
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
317
|
+
this.hsl = hsl;
|
|
318
|
+
this.rgb = Tools.hslToRgb( hsl );
|
|
319
|
+
this.bcolor = Tools.rgbToHex( this.rgb );
|
|
320
|
+
this.update( true );
|
|
321
|
+
return this;
|
|
356
322
|
|
|
357
|
-
|
|
358
|
-
this.ctxOverlay.translate(this.mid, this.mid);
|
|
323
|
+
}
|
|
359
324
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
325
|
+
moveMarkers () {
|
|
326
|
+
|
|
327
|
+
let p = this.pp;
|
|
328
|
+
let T = Tools;
|
|
329
|
+
|
|
330
|
+
let c1 = this.invert ? '#fff' : '#000';
|
|
331
|
+
let a = this.hsl[0] * T.TwoPI;
|
|
332
|
+
let third = (2/3) * T.PI;
|
|
333
|
+
let r = this.tr;
|
|
334
|
+
let h = this.hsl[0];
|
|
335
|
+
let s = this.hsl[1];
|
|
336
|
+
let l = this.hsl[2];
|
|
337
|
+
|
|
338
|
+
let angle = ( a - T.pi90 ) * T.todeg;
|
|
339
|
+
|
|
340
|
+
h = - a + T.pi90;
|
|
341
|
+
|
|
342
|
+
let hx = Math.cos(h) * r;
|
|
343
|
+
let hy = -Math.sin(h) * r;
|
|
344
|
+
let sx = Math.cos(h - third) * r;
|
|
345
|
+
let sy = -Math.sin(h - third) * r;
|
|
346
|
+
let vx = Math.cos(h + third) * r;
|
|
347
|
+
let vy = -Math.sin(h + third) * r;
|
|
348
|
+
let mx = (sx + vx) / 2, my = (sy + vy) / 2;
|
|
349
|
+
a = (1 - 2 * Math.abs(l - .5)) * s;
|
|
350
|
+
let x = sx + (vx - sx) * l + (hx - mx) * a;
|
|
351
|
+
let y = sy + (vy - sy) * l + (hy - my) * a;
|
|
352
|
+
|
|
353
|
+
p.set( x, y ).addScalar(128);
|
|
354
|
+
|
|
355
|
+
//let ff = (1-l)*255;
|
|
356
|
+
// this.setSvg( this.c[3], 'stroke', 'rgb('+ff+','+ff+','+ff+')', 3 );
|
|
357
|
+
|
|
358
|
+
this.setSvg( this.c[3], 'transform', 'rotate('+angle+' )', 2 );
|
|
359
|
+
|
|
360
|
+
this.setSvg( this.c[3], 'cx', p.x, 3 );
|
|
361
|
+
this.setSvg( this.c[3], 'cy', p.y, 3 );
|
|
362
|
+
|
|
363
|
+
this.setSvg( this.c[3], 'stroke', this.invert ? '#fff' : '#000', 2, 3 );
|
|
364
|
+
this.setSvg( this.c[3], 'stroke', this.invert ? '#fff' : '#000', 3 );
|
|
365
|
+
this.setSvg( this.c[3], 'fill',this.bcolor, 3 );
|
|
366
|
+
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
rSize () {
|
|
370
|
+
|
|
371
|
+
//Proto.prototype.rSize.call( this );
|
|
372
|
+
super.rSize();
|
|
373
|
+
|
|
374
|
+
let s = this.s;
|
|
375
|
+
|
|
376
|
+
s[2].width = this.sb + 'px';
|
|
377
|
+
s[2].left = this.sa + 'px';
|
|
378
|
+
|
|
379
|
+
this.rSizeColor( this.cw );
|
|
380
|
+
|
|
381
|
+
this.decal.x = Math.floor((this.w - this.wfixe) * 0.5);
|
|
382
|
+
//s[3].left = this.decal.x + 'px';
|
|
383
|
+
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
rSizeColor ( w ) {
|
|
387
|
+
|
|
388
|
+
if( w === this.wfixe ) return;
|
|
389
|
+
|
|
390
|
+
this.wfixe = w;
|
|
391
|
+
|
|
392
|
+
let s = this.s;
|
|
393
|
+
|
|
394
|
+
//this.decal.x = Math.floor((this.w - this.wfixe) * 0.5);
|
|
395
|
+
this.decal.y = this.side === 'up' ? 2 : this.baseH + 2;
|
|
396
|
+
this.mid = Math.floor( this.wfixe * 0.5 );
|
|
397
|
+
|
|
398
|
+
this.setSvg( this.c[3], 'viewBox', '0 0 '+ this.wfixe + ' '+ this.wfixe );
|
|
399
|
+
s[3].width = this.wfixe + 'px';
|
|
400
|
+
s[3].height = this.wfixe + 'px';
|
|
401
|
+
//s[3].left = this.decal.x + 'px';
|
|
402
|
+
s[3].top = this.decal.y + 'px';
|
|
403
|
+
|
|
404
|
+
this.ratio = 256 / this.wfixe;
|
|
405
|
+
this.square = 1 / (60*(this.wfixe/256));
|
|
406
|
+
this.setHeight();
|
|
407
|
+
|
|
408
|
+
}
|
|
366
409
|
|
|
367
|
-
};
|
|
368
410
|
|
|
369
|
-
|
|
411
|
+
}
|