Advertisement
KoctrX

Untitled

Dec 25th, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. xProcess: function (val) {
  2. if (val === 0) return;
  3. const Aya = 0 <= val ? {
  4. r: [{ x: 0, y: 0 }, { x: 77, y: 26 }, { x: 179, y: 204 }, { x: 255, y: 255 }],
  5. g: [{ x: 0, y: 0 }, { x: 64, y: 38 }, { x: 191, y: 217 }, { x: 255, y: 255 }],
  6. b: [{ x: 0, y: 0 }, { x: 85, y: 102 }, { x: 170, y: 153 }, { x: 255, y: 204 }]
  7. } : {
  8. r: [{ x: 0, y: 0 }, { x: 77, y: 26 }, { x: 179, y: 51 }, { x: 242, y: 255 }],
  9. g: [{ x: 0, y: 0 }, { x: 64, y: 102 }, { x: 153, y: 153 }, { x: 255, y: 255 }],
  10. b: [{ x: 0, y: 0 }, { x: 77, y: 79 }, { x: 153, y: 153 }, { x: 255, y: 255 }]
  11. };
  12.  
  13. val = Math.abs(val);
  14. var a;
  15. var b = {
  16. mh: 70,
  17. Aya
  18. };
  19. const c = val / 100;
  20. var d = h => {
  21. let l = h.x;
  22. return { x: l, y: (1 - c) * l + h.y * c };
  23. };
  24.  
  25. class nza {
  26. constructor(a, b) {
  27. this.J3b = a;
  28. this.xs = b
  29. }
  30.  
  31. interpolate(a) {
  32. var b = this.J3b;
  33. const c = this.xs;
  34. let d = 0,
  35. e = this.J3b.length - 1;
  36.  
  37. for (; 1 < e - d;) {
  38. var f = e + d >> 1;
  39. b[f].x > a ? e = f : d = f
  40. }
  41. f = b[e];
  42. b = b[d];
  43. const g = f.x - b.x,
  44. h = (f.x - a) / g;
  45. a = (a - b.x) / g;
  46.  
  47. return h * b.y + a * f.y + (c[d] * (h ** 3 - h) + c[e] * (a ** 3 - a)) * g ** 2 / 6;
  48. }
  49. }
  50.  
  51. function Xr(a) {
  52. var b = a.length;
  53.  
  54. const c = new Float64Array(b),
  55. d = new Float64Array(b);
  56. for (let e = 1; e < b - 1; e++) {
  57. const f = a[e - 1],
  58. g = a[e],
  59. h = a[e + 1],
  60. l = h.x - f.x,
  61. p = (g.x - f.x) / l,
  62. q = p * d[e - 1] + 2;
  63. c[e] = (6 * ((h.y - g.y) / (h.x - g.x) - (g.y - f.y) / (g.x - f.x)) / l - p * c[e - 1]) / q;
  64. d[e] = (p - 1) / q
  65. }
  66. for (b -= 2; 0 <= b; --b) d[b] = d[b] * d[b + 1] + c[b];
  67.  
  68. return new nza(a, d);
  69. };
  70.  
  71. a = Xr(Aya.r.map(d));
  72. const e = Xr(Aya.g.map(d));
  73. b = Xr(Aya.b.map(d));
  74. d = Array(32);
  75. const f = Array(32),
  76. g = Array(32);
  77. for (let h = 0; 32 > h; h++) {
  78. const l = 255 * h / 31;
  79. d[h] = Math.max(0, Math.min(255, a.interpolate(l))) / 255;
  80. f[h] = Math.max(0, Math.min(255, e.interpolate(l))) / 255;
  81. g[h] = Math.max(0, Math.min(255, b.interpolate(l))) / 255;
  82. }
  83.  
  84. return { r: d, g: f, b: g };
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement