Skip to content

Commit 9f997ff

Browse files
committed
added constant velocity mode to Emitter_Fountain
added globalBrightness to FastLEDRenderer added constructor with x,y position to Particle_Fixed
1 parent 5c609ec commit 9f997ff

6 files changed

+50
-13
lines changed

Emitter_Fountain.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ Emitter_Fountain::Emitter_Fountain(int16_t vx, int16_t vy, byte var, Particle_Ab
2323
this->var = var;
2424
this->_hVar = (var>>1);
2525
this->source = source;
26+
_constVel = 0;
27+
counter = 0;
28+
29+
}
30+
Emitter_Fountain::Emitter_Fountain(uint16_t constVel, Particle_Abstract *source)
31+
{
32+
this->vx = 0;
33+
this->vy = 0;
34+
this->var = 0;
35+
if(constVel > 32767) { constVel = 32767; }
36+
_constVel = constVel;
37+
this->_hVar = (_constVel<<1);
38+
this->source = source;
2639
counter = 0;
2740
}
2841

@@ -38,8 +51,14 @@ void Emitter_Fountain::emit(Particle_Abstract *particle, ParticleSysConfig *g)
3851

3952
particle->x = source->x;
4053
particle->y = source->y;
41-
particle->vx = vx + random(var)-_hVar;
42-
particle->vy = vy + random(var)-_hVar;
54+
if(_constVel > 0) {
55+
particle->vx = random(_hVar)-_constVel;
56+
particle->vy = sqrt(pow(_constVel,2)-pow(particle->vx,2));
57+
if(random(8)<3) { particle->vy=-particle->vy; }
58+
} else {
59+
particle->vx = vx + random(var)-_hVar;
60+
particle->vy = vy + random(var)-_hVar;
61+
}
4362
particle->ttl = random(minLife, maxLife);
4463
particle->hue = counter%255;
4564
particle->isAlive = true;

Emitter_Fountain.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ class Emitter_Fountain : public Emitter_Abstract {
2929
unsigned int counter;
3030

3131
Emitter_Fountain(int16_t vx, int16_t vy, byte var, Particle_Abstract *source);
32+
Emitter_Fountain(uint16_t constVel, Particle_Abstract *source);
3233
void emit(Particle_Abstract *particle, ParticleSysConfig *g);
3334
void update(ParticleSysConfig *g);
3435
private:
35-
byte _hVar;
36+
uint16_t _hVar;
37+
uint16_t _constVel;
3638
};
3739

3840
#endif /* emitter_fountain_h */

FastLEDRenderer.cpp

+16-9
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ void FastLEDRenderer::init(ParticleSysConfig *g, uint8_t left, uint8_t top, uint
4242
this->height = height;
4343
this->crop_left = crop_left;
4444
this->crop_top = crop_top;
45+
this->globalBrightness = 255;
4546
}
4647

4748
/* GMA hier - change below ########################################################## */
4849

4950
void FastLEDRenderer::render(ParticleSysConfig *g, Particle_Abstract particles[], byte numParticles, CRGB *_leds) {
5051
byte row, col;
5152
uint16_t dx, dy;
52-
unsigned long tempVal;
53+
uint8_t tempVal;
5354
CRGB baseRGB;
5455

5556
//go over particles and update matrix cells on the way
@@ -74,36 +75,42 @@ void FastLEDRenderer::render(ParticleSysConfig *g, Particle_Abstract particles[]
7475
//bottom left
7576
col = part_x / g->res_x;
7677
row = part_y / g->res_y;
77-
tempVal = ((unsigned long)dx*dy*particles[i].ttl)/g->res_area;
78-
if(tempVal > 255) {tempVal = 255;}
78+
tempVal = calcTempVal(g,dx,dy,particles[i].ttl);
7979
addColor(col, row, &baseRGB, tempVal, _leds);
8080

8181
//bottom right;
8282
col++;
8383
if (col < g->width) {
84-
tempVal = ((unsigned long)(g->res_x-dx)*dy*particles[i].ttl)/g->res_area;
85-
if(tempVal > 255) {tempVal = 255;}
84+
tempVal = calcTempVal(g,(g->res_x-dx),dy,particles[i].ttl);
8685
addColor(col, row, &baseRGB, tempVal, _leds);
8786
}
8887

8988
//top right
9089
row++;
9190
if (col < g->width && row < g->height) {
92-
tempVal = ((unsigned long)(g->res_x-dx)*(g->res_y-dy)*particles[i].ttl)/g->res_area;
93-
if(tempVal > 255) {tempVal = 255;}
91+
tempVal = calcTempVal(g,(g->res_x-dx),(g->res_y-dy),particles[i].ttl);
9492
addColor(col, row, &baseRGB, tempVal, _leds);
9593
}
9694

9795
//top left
9896
col--;
9997
if (row < g->height) {
100-
tempVal = ((unsigned long)dx*(g->res_y-dy)*particles[i].ttl)/g->res_area;
101-
if(tempVal > 255) {tempVal = 255;}
98+
tempVal = calcTempVal(g,dx,(g->res_y-dy),particles[i].ttl);
10299
addColor(col, row, &baseRGB, tempVal, _leds);
103100
}
104101
}
105102
}
106103

104+
uint8_t FastLEDRenderer::calcTempVal(ParticleSysConfig *g, uint16_t dx, uint16_t dy, uint8_t ttl) {
105+
uint8_t _ttl = ttl;
106+
if(globalBrightness < 255) {
107+
_ttl = scale8(_ttl,globalBrightness);
108+
}
109+
unsigned long r = ((unsigned long)dx*dy*_ttl)/g->res_area;
110+
if(r > 255)
111+
return 255;
112+
return r;
113+
}
107114

108115
void FastLEDRenderer::addColor(byte col, byte row, CRGB *colorRGB, byte value, CRGB *_leds) {
109116
if(col >= width || row >= height) // check if pixel is outside of the render area

FastLEDRenderer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ class FastLEDRenderer {
2929
void reset(CRGB *_leds); //set each pixel to 0
3030
void fade(CRGB *_leds); //divide each pixel by half
3131
void fadeBy(byte amount, CRGB *_leds); //substract amount from each pixel
32-
32+
uint8_t globalBrightness;
3333
private:
3434
uint8_t left,top,width,height,crop_left,crop_top;
3535
void init(ParticleSysConfig *g, uint8_t left, uint8_t top, uint8_t width, uint8_t height, uint8_t crop_left, uint8_t crop_top);
3636
void addColor(byte col, byte row, CRGB *rgb, byte value, CRGB *_leds);
37+
uint8_t calcTempVal(ParticleSysConfig *g, uint16_t dx, uint16_t dy, uint8_t ttl);
3738
};
3839

3940
// we need to declare this function here, otherwise there are errors while compiling...

Particle_Fixed.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ Particle_Fixed::Particle_Fixed()
1919
{
2020
isAlive = 0;
2121
}
22+
Particle_Fixed::Particle_Fixed(uint16_t x, uint16_t y) {
23+
this->x = x;
24+
this->y = y;
25+
this->vx = 0;
26+
this->vy = 0;
27+
this->isAlive = 0;
28+
}
2229

2330
void Particle_Fixed::update(ParticleSysConfig *g)
2431
{

Particle_Fixed.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Particle_Fixed : public Particle_Abstract {
2020
public:
2121
static byte decayFactor;
2222
Particle_Fixed();
23+
Particle_Fixed(uint16_t x, uint16_t y);
2324
void update(ParticleSysConfig *g);
2425
};
2526

0 commit comments

Comments
 (0)