mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Lint fixes and related cleanup
This commit is contained in:
parent
369c02b5d5
commit
a6190da774
3 changed files with 55 additions and 28 deletions
|
@ -81,9 +81,9 @@ Scratch3PenBlocks.prototype._getPenState = function (target) {
|
|||
|
||||
/**
|
||||
* Handle a target which has moved. This only fires when the pen is down.
|
||||
* @param {RenderedTarget} target
|
||||
* @param {number} oldX
|
||||
* @param {number} oldY
|
||||
* @param {RenderedTarget} target - the target which has moved.
|
||||
* @param {number} oldX - the previous X position.
|
||||
* @param {number} oldY - the previous Y position.
|
||||
* @private
|
||||
*/
|
||||
Scratch3PenBlocks.prototype._onTargetMoved = function (target, oldX, oldY) {
|
||||
|
|
|
@ -166,7 +166,8 @@ RenderedTarget.prototype.setXY = function (x, y) {
|
|||
if (this.isStage) {
|
||||
return;
|
||||
}
|
||||
var oldX = this.x, oldY = this.y;
|
||||
var oldX = this.x;
|
||||
var oldY = this.y;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
if (this.renderer) {
|
||||
|
|
|
@ -99,14 +99,10 @@ Color.hexToDecimal = function (hex) {
|
|||
* @returns {RGBObject} rgb - {r: red [0,255], g: green [0,255], b: blue [0,255]}.
|
||||
*/
|
||||
Color.hsvToRgb = function (hsv) {
|
||||
var h = hsv.h;
|
||||
var s = hsv.s;
|
||||
var v = hsv.v;
|
||||
|
||||
h = h % 360;
|
||||
var h = hsv.h % 360;
|
||||
if (h < 0) h += 360;
|
||||
s = Math.max(0, Math.min(s, 1));
|
||||
v = Math.max(0, Math.min(v, 1));
|
||||
var s = Math.max(0, Math.min(hsv.s, 1));
|
||||
var v = Math.max(0, Math.min(hsv.v, 1));
|
||||
|
||||
var i = Math.floor(h / 60);
|
||||
var f = (h / 60) - i;
|
||||
|
@ -114,13 +110,43 @@ Color.hsvToRgb = function (hsv) {
|
|||
var q = v * (1 - (s * f));
|
||||
var t = v * (1 - (s * (1 - f)));
|
||||
|
||||
var r, g, b;
|
||||
if (i == 0) { r = v; g = t; b = p; }
|
||||
else if (i == 1) { r = q; g = v; b = p; }
|
||||
else if (i == 2) { r = p; g = v; b = t; }
|
||||
else if (i == 3) { r = p; g = q; b = v; }
|
||||
else if (i == 4) { r = t; g = p; b = v; }
|
||||
else if (i == 5) { r = v; g = p; b = q; }
|
||||
var r;
|
||||
var g;
|
||||
var b;
|
||||
|
||||
switch (i) {
|
||||
default:
|
||||
case 0:
|
||||
r = v;
|
||||
g = t;
|
||||
b = p;
|
||||
break;
|
||||
case 1:
|
||||
r = q;
|
||||
g = v;
|
||||
b = p;
|
||||
break;
|
||||
case 2:
|
||||
r = p;
|
||||
g = v;
|
||||
b = t;
|
||||
break;
|
||||
case 3:
|
||||
r = p;
|
||||
g = q;
|
||||
b = v;
|
||||
break;
|
||||
case 4:
|
||||
r = t;
|
||||
g = p;
|
||||
b = v;
|
||||
break;
|
||||
case 5:
|
||||
r = v;
|
||||
g = p;
|
||||
b = q;
|
||||
break;
|
||||
}
|
||||
|
||||
return {
|
||||
r: Math.floor(r * 255),
|
||||
|
@ -135,18 +161,18 @@ Color.hsvToRgb = function (hsv) {
|
|||
* @returns {HSVObject} hsv - {h: hue [0,360), s: saturation [0,1], v: value [0,1]}
|
||||
*/
|
||||
Color.rgbToHsv = function (rgb) {
|
||||
var v, x, f, i;
|
||||
var h = 0, s = 0;
|
||||
var r = rgb.r;
|
||||
var g = rgb.g;
|
||||
var b = rgb.b;
|
||||
x = Math.min(Math.min(r, g), b);
|
||||
v = Math.max(Math.max(r, g), b);
|
||||
var x = Math.min(Math.min(r, g), b);
|
||||
var v = Math.max(Math.max(r, g), b);
|
||||
|
||||
// For grays, hue will be arbitrarily reported as zero. Otherwise, calculate
|
||||
if (x != v) {
|
||||
f = (r == x) ? g - b : ((g == x) ? b - r : r - g);
|
||||
i = (r == x) ? 3 : ((g == x) ? 5 : 1);
|
||||
var h = 0;
|
||||
var s = 0;
|
||||
if (x !== v) {
|
||||
var f = (r === x) ? g - b : ((g === x) ? b - r : r - g);
|
||||
var i = (r === x) ? 3 : ((g === x) ? 5 : 1);
|
||||
h = ((i - (f / (v - x))) * 60) % 360;
|
||||
s = (v - x) / v;
|
||||
}
|
||||
|
@ -166,9 +192,9 @@ Color.mixRgb = function (rgb0, rgb1, fraction1) {
|
|||
if (fraction1 >= 1) return rgb1;
|
||||
var fraction0 = 1 - fraction1;
|
||||
return {
|
||||
r: fraction0 * rgb0.r + fraction1 * rgb1.r,
|
||||
g: fraction0 * rgb0.g + fraction1 * rgb1.g,
|
||||
b: fraction0 * rgb0.b + fraction1 * rgb1.b
|
||||
r: (fraction0 * rgb0.r) + (fraction1 * rgb1.r),
|
||||
g: (fraction0 * rgb0.g) + (fraction1 * rgb1.g),
|
||||
b: (fraction0 * rgb0.b) + (fraction1 * rgb1.b)
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue