ESP8266-RGB5m/Particle.cpp

49 lines
863 B
C++

#include "Particle.h"
#include "NeoPatterns.h"
Particle::Particle() // Particle::Particle(NeoPatterns * parent)
{
_pos = 0;
// _id = parent->maxParticleID;
// parent->maxParticleID++;
} //Default constructor.
Particle::Particle(NeoPatterns * parent, float pos, float speed, uint8_t hue, float brightness, float decay )
{
_id = parent->maxParticleID;
parent->maxParticleID++;
_pos = pos;
_speed = speed;
_hue = hue;
_brightness = brightness;
_decay = decay;
_parent = parent;
}
bool Particle::operator==(const Particle &p) const {
return (p._id == _id);
}
void Particle::update()
{
_pos += _speed;
_speed *= 0.96;
_brightness *= _decay;
if (_pos > _parent->numPixels()) {
_pos = 0;
}
_parent->setPixelColor((int)_pos, _parent->Wheel(_hue, _brightness));
}
float Particle::brightness()
{
return _brightness;
}