Skip to content

Commit 027f3a7

Browse files
committed
better blur (maybe?)
1 parent 8ae7ead commit 027f3a7

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

Diff for: ledarray.cpp

+40-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ void LEDArray::rotate_hue(){
5656

5757
}
5858

59+
uint8_t blend_hues(uint8_t one, uint8_t two){
60+
long diff=one-two;
61+
long avg;
62+
if(abs(diff)<128){
63+
avg=0.5*one+0.5*two;
64+
} else {
65+
avg=((long) (0.5*one+0.5*two+128)) % 256;
66+
}
67+
68+
return (uint8_t) avg-1;
69+
}
5970

6071
void LEDArray::blur(){
6172
CHSV prev=CHSV(random(255),255,255);
@@ -64,12 +75,39 @@ void LEDArray::blur(){
6475
int i;
6576
for(i=0; i<num_leds-1; i++){
6677
CHSV next=rgb2hsv_approximate(leds[i+1]);
67-
leds[i]=CHSV(0.3*prev.hue+0.4*current.hue+0.3*prev.hue,255,255);
78+
leds[i]=CHSV(blend_hues(current.hue,blend_hues(prev.hue,next.hue)),255,255);
6879
prev=current;
6980
current=next;
7081
}
7182

7283
next=CHSV(random(255),255,255);
73-
leds[i]=CHSV(0.3*prev.hue+0.4*current.hue+0.3*prev.hue,255,255);
84+
leds[i]=CHSV(blend_hues(current.hue,blend_hues(prev.hue,next.hue)),255,255);
85+
}
86+
87+
88+
void LEDArray::rand_swap(){
89+
long pos=random(num_leds);
90+
long pos2=random(num_leds);
91+
CRGB tmp = leds[pos];
92+
leds[pos] = leds[pos2];
93+
leds[pos2] = tmp;
94+
}
95+
96+
void LEDArray::rand_swapn(){
97+
for(int i=0; i<100; i++){
98+
rand_swap();
99+
}
100+
}
101+
102+
103+
void LEDArray::rand_hue(){
104+
long pos=random(num_leds);
105+
leds[pos] = CHSV(random(255),255,255);
106+
}
107+
108+
void LEDArray::rand_huen(){
109+
for(int i=0; i<100; i++){
110+
rand_hue();
111+
}
74112
}
75113

Diff for: ledarray.h

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class LEDArray
1515
void rotate();
1616
void rotate_hue();
1717
void blur();
18+
void rand_swap();
19+
void rand_swapn();
20+
void rand_hue();
21+
void rand_huen();
1822
//private:
1923
long num_leds;
2024
struct CRGB *leds;

Diff for: noise.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Noise : public Animation {
1515
void step(LEDArray *ledarray)
1616
{
1717
//ledarray->rotate_hue();
18+
ledarray->rand_hue();
1819
ledarray->blur();
1920
FastLED.show();
2021
}

0 commit comments

Comments
 (0)