qwewqeqwe
This commit is contained in:
parent
bcc524ee5b
commit
5ce6777157
1 changed files with 27 additions and 8 deletions
35
lights.js
35
lights.js
|
@ -70,22 +70,38 @@ function fade(index) {
|
|||
var diff_r = final.r - original.r;
|
||||
var diff_cr = current.r - original.r;
|
||||
var diff_g = final.g - original.g;
|
||||
var diff_cg = current.g - original.g;
|
||||
var diff_b = final.b - original.b;
|
||||
var interval_r = diff_r / fade_ticks;
|
||||
var interval_g = diff_g / fade_ticks;
|
||||
var interval_b = diff_b / fade_ticks;
|
||||
var diff_cb = current.b - original.b;
|
||||
var interval_r = Math.ceil(diff_r / fade_ticks);
|
||||
var interval_g = Math.ceil(diff_g / fade_ticks);
|
||||
var interval_b = Math.ceil(diff_b / fade_ticks);
|
||||
|
||||
var current_tick = Math.floor((diff_cr / diff_r) * fade_ticks);
|
||||
var current_tick_r = Math.abs(Math.floor((diff_cr / diff_r) * fade_ticks));
|
||||
var current_tick_g = Math.abs(Math.floor((diff_cg / diff_g) * fade_ticks));
|
||||
var current_tick_b = Math.abs(Math.floor((diff_cb / diff_b) * fade_ticks));
|
||||
|
||||
if (diff_r == 0) {
|
||||
current_tick = fade_ticks;
|
||||
}
|
||||
// console.log(`original: ${original.r} ${original.g} ${original.b}\n` +
|
||||
// `current: ${current.r} ${current.g} ${current.b}\n` +
|
||||
// `final: ${final.r} ${final.g} ${final.b}\n` +
|
||||
// `interval: ${interval_r} ${interval_g} ${interval_b}\n`)
|
||||
|
||||
if (current_tick + 1 >= fade_ticks) {
|
||||
if (Math.abs(current.r + interval_r) >= Math.abs(final.r)) {
|
||||
current.r = final.r;
|
||||
interval_r = 0;
|
||||
}
|
||||
if (Math.abs(current.g + interval_g) >= Math.abs(final.g)) {
|
||||
current.g = final.g;
|
||||
interval_g = 0;
|
||||
}
|
||||
if (Math.abs(current.b + interval_b) >= Math.abs(final.b)) {
|
||||
current.b = final.b;
|
||||
interval_b = 0;
|
||||
}
|
||||
|
||||
if (current_tick_r + 1 >= fade_ticks &&
|
||||
current_tick_g + 1 >= fade_ticks &&
|
||||
current_tick_b + 1 >= fade_ticks) {
|
||||
pixels[index] = next_pattern[index];
|
||||
pixel_cache[index] = next_pattern[index];
|
||||
}
|
||||
|
@ -93,5 +109,8 @@ function fade(index) {
|
|||
pixels[index] = rgb_to_int(current.r + interval_r,
|
||||
current.g + interval_g,
|
||||
current.b + interval_b);
|
||||
console.log(`${current_tick_r} ${current_tick_g} ${current_tick_b}: `
|
||||
+ `NEW COLOR: ${current.r} ${current.g} ${current.b} FINAL: ${final.r} ${final.g} ${final.b} ` +
|
||||
`INTERVAL: ${interval_r} ${interval_g} ${interval_b}`);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue