-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticleEmitter.cpp
More file actions
executable file
·76 lines (57 loc) · 1.92 KB
/
ParticleEmitter.cpp
File metadata and controls
executable file
·76 lines (57 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
Arduino library to simulate particle emission with an RGB LED strip.
Copyright (C) Stumpware
MIT license
*/
#include "ParticleEmitter.h"
#define MAX_COLOR 127
/*****************************************************************************/
ParticleEmitter::ParticleEmitter(uint16_t n) {
numPixels = n;
numParticles = MAX_PARTICLES;
maxVelocity = float(numParticles / 2000.0);
stripPosition = random(100) / 100.0; // 0.0 - 1.0
for (int i=0; i < MAX_PARTICLES; i++) {
particles[i] = newParticle();
}
}
particle ParticleEmitter::newParticle() {
particle p;
int8_t direction = (random(2) == 0 ? 1 : -1);
// uint8_t maxColor = (random(2) == 0 ? MAX_COLOR/(random(35)+5) : 0);
uint8_t maxColor = MAX_COLOR/(random(20)+5);
p.velocity = ((random(99) + 1) / 100.0) * direction;
if (direction > 0) {
p.redColor = random(maxColor);
p.greenColor = random(maxColor*0.25);
p.blueColor = random(maxColor*0.75);
}
else {
p.redColor = random(maxColor);
p.greenColor = random(maxColor*0.25);
p.blueColor = random(maxColor*0.75);
}
p.startTime = millis();
p.startStripPosition = stripPosition;
p.currentStripPosition = p.startStripPosition;
return p;
}
void ParticleEmitter::begin(void) {
}
particle ParticleEmitter::updateParticle(uint16_t i) {
particle *p = &particles[i];
p->currentStripPosition = p->currentStripPosition +
(maxVelocity * p->velocity); // *
//float(millis() - p->startTime);
if (0) {
if (p->currentStripPosition < 0.0)
p->currentStripPosition = 1.0;
else if (p->currentStripPosition > 1.0)
p->currentStripPosition = 0.0;
}
else {
if (p->currentStripPosition < -1.0 || p->currentStripPosition > 2.0)
*p = newParticle();
}
return *p;
}