Skip to content

Reversing the direction for comet doesn't work (includes working code) #25

@spikerXneh

Description

@spikerXneh

I noticed that reversing the direction for comet doesn't work. There is no logic to handle the -1. I updated my local version with a working version of it but unsure if this library is still being maintained but i've added my updated logic here in case it might help someone else.

class qpComet : public qpPattern {

    private:
        byte length;
        bool bounce;
        int pos = 0;
        int dir = 1;

        bool _inBounds(int pos) { return ((pos >= 0) && (pos < _numLeds)); }

    public:

        qpComet(byte length, bool bounce = false, int dir = 1) : length(length), bounce(bounce), dir(dir) { if (dir == -1){ pos = _numLeds;}}

        void draw() {
            
            if(_inBounds(this->pos))
                _targetLeds[this->pos] = _getColor();

            if(_inBounds(this->pos - (this->length*this->dir)))
                _targetLeds[(this->pos - (this->length*this->dir))] = CRGB::Black;
            
            if((this->pos >= (_numLeds + this->length)) || (this->pos <= (0 - this->length))) {
                if(this->bounce)
                    this->dir *= -1;
                else
					if(dir == -1){
						this->pos = _numLeds;
					}else{
						this->pos = 0;    
					}
                    
                _countCycle();
            }

            this->pos += this->dir;            
      }

};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions