Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@spikerXneh

Description

@spikerXneh
Issue body actions

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;            
      }

};
Reactions are currently unavailable

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.