Program Listing for File plasmaanimation.cpp

Return to documentation for file (src/animation/plasmaanimation.cpp)

#include <math.h>
#include "plasmaanimation.h"

namespace PixelMaestro {
    PlasmaAnimation::PlasmaAnimation(Section& section) : Animation(section) {
        type_ = AnimationType::Plasma;
        map();
    }

    float PlasmaAnimation::get_resolution() const {
        return resolution_;
    }

    float PlasmaAnimation::get_size() const {
        return size_;
    }

    void PlasmaAnimation::map() {
        for (uint16_t y = 0; y < dimensions_.y; y++) {
            for (uint16_t x = 0; x < dimensions_.x; x++) {
                set_map_color_index(x, y, ((resolution_ + (resolution_ * sin(x / size_))) + (resolution_ + (resolution_ * sin(y / size_)))) / 2);
            }
        }
    }

    void PlasmaAnimation::set_resolution(float resolution) {
        this->resolution_ = resolution;
        map();
    }

    void PlasmaAnimation::set_size(float size) {
        this->size_ = size;
        map();
    }

    void PlasmaAnimation::update() {
        update_cycle(0, palette_->get_num_colors());
    }
}