<commit_before>//
//  FlantsScene.cpp
//  show
//
//  Created by <NAME> on 05/09/2015.
//
//

#include "FlantsScene.h"
using namespace ofxCv;
using namespace cv;

FlantsScene::FlantsScene() {
    name = "Flants";
}

void FlantsScene::setup() {
    // subscenes
    subsceneStart = 51;
    subsceneEnd = 62;
    radius = 0;
    isFirstPlay = true;
    alphaShader.load("shaders/greyscaleAlpha.vert", "shaders/greyscaleAlpha.frag");
    SceneBase::setup();
}

void FlantsScene::update() {
    if (isMaster() && state == INTERACTIVE) {
        
        // contour tracker
        ContourTracker& tracker = *vision->getTracker();
        ofxCv::ContourFinder& contourFinder = tracker.contourFinder;
        float scale = displays->masterProjection.sizeIn->x / tracker.thresholded.width;
        float targetW = displays->masterProjection.sizeIn->x;
        float targetH = tracker.thresholded.height * scale;
        
        if (mode == YELLOW_SMALL || mode == RED_SMALL) {
            radius = ofLerp(radius, radiusSmall, 0.1);
        } else if (mode == EXPLODE) {
            radius = radiusLarge * 2;
        } else {
            radius = ofLerp(radius, radiusLarge, 0.1);
        }
        
        if (isFirstPlay) {
            revertBgLearn = tracker.bgLearningTime;
            isFirstPlay = false;
        }
        tracker.bgLearningTime = eatRate;
        
        particles.colorInhibitor = colorInhibitor;
        particles.attractPoints.clear();
        for(int i = 0; i < contourFinder.size(); i++) {
            // blob rect and position
            auto rect = toOf(contourFinder.getBoundingRect(i));
            auto center = toOf(contourFinder.getCenter(i));
            particles.attractPoints.push_back(ofRectangle(rect.x*scale, rect.y*scale, rect.width*scale, rect.height*scale));
        }
        ofPoint centre = ofPoint(displays->masterProjection.sizeIn.get().x/2, displays->masterProjection.sizeIn.get().y/2);
        particles.bounds.setFromCenter(centre, radius, radius);
        particles.update();
        
        if (mode == YELLOW_SMALL || mode == YELLOW_BLUE_SHAPES || mode == RED_SMALL || mode == RED_BLUE_SHAPES) {
            if (particles.allFull) {
                particles.resetEating();
                nextSubscene();
                cout<<"entering Next Scene"<<endl;
            }
        }
    }
    SceneBase::update();
}

void FlantsScene::draw() {
    SceneBase::draw();
}

void FlantsScene::drawMasterProjection() {
    ofSetColor(255);
    
    // contour tracker
    ContourTracker& tracker = *vision->getTracker();
    ofxCv::ContourFinder& contourFinder = tracker.contourFinder;
    float scale = displays->masterProjection.sizeIn->x / tracker.thresholded.width;
    float targetW = displays->masterProjection.sizeIn->x;
    float targetH = tracker.thresholded.height * scale;
    tracker.thresholded.draw(0, 0, targetW, targetH);

    if (mode == YELLOW_BLUE_SHAPES || mode == RED_BLUE_SHAPES) {
        // Draw the background shapes FBO into a shader
        // Anything with r == 0 is made transparent
        alphaShader.begin();
        alphaShader.setUniformTexture("tex0", particles.background.getTextureReference(), 0);
        particles.background.draw(0,0);
        alphaShader.end();
    }
    // particles
    particles.draw();
}

//////////////////////////////////////////////////////////////////////////////////
// public
//////////////////////////////////////////////////////////////////////////////////
void FlantsScene::play(int i){
    if (isMaster()) {
        vision->isEnabled = true;
        if (i == 51) {
            setMode(YELLOW_SMALL);
            countdown->stop();
            osc->sendLightSoundCue(cues[0]);
        }
        else if (i == 52) {
            setMode(YELLOW_EXPAND);
            countdown->start(timerTransition);
            osc->sendLightSoundCue(cues[1]);
        }
        else if (i == 53) {
            setMode(YELLOW_BLUE_SHAPES);
            countdown->stop();
            osc->sendLightSoundCue(cues[2]);
        }
        else if (i == 54) {
            setMode(RED_SMALL);
            countdown->stop();
            osc->sendLightSoundCue(cues[3]);
        }
        else if (i == 55 || i == 59) {
            setMode(RED_EXPAND);
            countdown->start(timerTransition);
            osc->sendLightSoundCue(cues[4]);
        }
        else if (i == 56 || i == 60) {
            setMode(RED_BLUE_SHAPES);
            countdown->stop();
            osc->sendLightSoundCue(cues[5]);
        }
        else if (i == 57 || i == 61) {
            setMode(EXPLODE);
            countdown->start(timerBoom);
            osc->sendLightSoundCue(cues[6]);
        }
        else if (i == 58) {
            setMode(EXPLODE);
            countdown->start(timerGameOver + timerAgain);
            osc->sendLightSoundCue(cues[7]);
        }
        else if (i == 62) {
            countdown->start(17 /*timerGameOver + timerTired + timerNext*/);
            osc->sendLightSoundCue(cues[8]);
        }
    }
    
    // LED title
    if (isSlave()) {
        if ( (i>50 && i<57) || (i>58 && i<61) ) {
            led->show(title.get());
        }
        else if (i == 57 || i == 61) {
            led->show(boom.get());
        }
        else if (i == 58) {
            led->hide();
            led->queue(LedDisplay::Params(gameOver.get(), 0, timerGameOver, 0, false, 0));
            led->queue(LedDisplay::Params(playAgain.get(), 0, timerAgain, 0, false, 0));
            led->playQueue();
        }
        else if (i == 62) {
            led->hide();
            led->queue(LedDisplay::Params(gameOver.get(), 0, 4, 0, false, 0));
            led->queue(LedDisplay::Params(tired.get(), 0, 8, 0, false, 0));
            led->queue(LedDisplay::Params(nextLevel.get(), 0, 5, 0, false, 5));
            led->playQueue();
        }
    }
    SceneBase::play(i);
}

void FlantsScene::stop(){;
    vision->getTracker()->bgLearningTime = revertBgLearn;
    isFirstPlay = true;
    SceneBase::stop();
}

void FlantsScene::setupGui() {
    guiName = "Flants";
    panel.setup(guiName, "settings/flants.xml");<commit_msg>Changed plants title to say nothing after explosion<commit_after>//
//  FlantsScene.cpp
//  show
//
//  Created by <NAME> on 05/09/2015.
//
//

#include "FlantsScene.h"
using namespace ofxCv;
using namespace cv;

FlantsScene::FlantsScene() {
    name = "Flants";
}

void FlantsScene::setup() {
    // subscenes
    subsceneStart = 51;
    subsceneEnd = 62;
    radius = 0;
    isFirstPlay = true;
    alphaShader.load("shaders/greyscaleAlpha.vert", "shaders/greyscaleAlpha.frag");
    SceneBase::setup();
}

void FlantsScene::update() {
    if (isMaster() && state == INTERACTIVE) {
        
        // contour tracker
        ContourTracker& tracker = *vision->getTracker();
        ofxCv::ContourFinder& contourFinder = tracker.contourFinder;
        float scale = displays->masterProjection.sizeIn->x / tracker.thresholded.width;
        float targetW = displays->masterProjection.sizeIn->x;
        float targetH = tracker.thresholded.height * scale;
        
        if (mode == YELLOW_SMALL || mode == RED_SMALL) {
            radius = ofLerp(radius, radiusSmall, 0.1);
        } else if (mode == EXPLODE) {
            radius = radiusLarge * 2;
        } else {
            radius = ofLerp(radius, radiusLarge, 0.1);
        }
        
        if (isFirstPlay) {
            revertBgLearn = tracker.bgLearningTime;
            isFirstPlay = false;
        }
        tracker.bgLearningTime = eatRate;
        
        particles.colorInhibitor = colorInhibitor;
        particles.attractPoints.clear();
        for(int i = 0; i < contourFinder.size(); i++) {
            // blob rect and position
            auto rect = toOf(contourFinder.getBoundingRect(i));
            auto center = toOf(contourFinder.getCenter(i));
            particles.attractPoints.push_back(ofRectangle(rect.x*scale, rect.y*scale, rect.width*scale, rect.height*scale));
        }
        ofPoint centre = ofPoint(displays->masterProjection.sizeIn.get().x/2, displays->masterProjection.sizeIn.get().y/2);
        particles.bounds.setFromCenter(centre, radius, radius);
        particles.update();
        
        if (mode == YELLOW_SMALL || mode == YELLOW_BLUE_SHAPES || mode == RED_SMALL || mode == RED_BLUE_SHAPES) {
            if (particles.allFull) {
                particles.resetEating();
                nextSubscene();
                cout<<"entering Next Scene"<<endl;
            }
        }
    }
    SceneBase::update();
}

void FlantsScene::draw() {
    SceneBase::draw();
}

void FlantsScene::drawMasterProjection() {
    ofSetColor(255);
    
    // contour tracker
    ContourTracker& tracker = *vision->getTracker();
    ofxCv::ContourFinder& contourFinder = tracker.contourFinder;
    float scale = displays->masterProjection.sizeIn->x / tracker.thresholded.width;
    float targetW = displays->masterProjection.sizeIn->x;
    float targetH = tracker.thresholded.height * scale;
    tracker.thresholded.draw(0, 0, targetW, targetH);

    if (mode == YELLOW_BLUE_SHAPES || mode == RED_BLUE_SHAPES) {
        // Draw the background shapes FBO into a shader
        // Anything with r == 0 is made transparent
        alphaShader.begin();
        alphaShader.setUniformTexture("tex0", particles.background.getTextureReference(), 0);
        particles.background.draw(0,0);
        alphaShader.end();
    }
    // particles
    particles.draw();
}

//////////////////////////////////////////////////////////////////////////////////
// public
//////////////////////////////////////////////////////////////////////////////////
void FlantsScene::play(int i){
    if (isMaster()) {
        vision->isEnabled = true;
        if (i == 51) {
            setMode(YELLOW_SMALL);
            countdown->stop();
            osc->sendLightSoundCue(cues[0]);
        }
        else if (i == 52) {
            setMode(YELLOW_EXPAND);
            countdown->start(timerTransition);
            osc->sendLightSoundCue(cues[1]);
        }
        else if (i == 53) {
            setMode(YELLOW_BLUE_SHAPES);
            countdown->stop();
            osc->sendLightSoundCue(cues[2]);
        }
        else if (i == 54) {
            setMode(RED_SMALL);
            countdown->stop();
            osc->sendLightSoundCue(cues[3]);
        }
        else if (i == 55 || i == 59) {
            setMode(RED_EXPAND);
            countdown->start(timerTransition);
            osc->sendLightSoundCue(cues[4]);
        }
        else if (i == 56 || i == 60) {
            setMode(RED_BLUE_SHAPES);
            countdown->stop();
            osc->sendLightSoundCue(cues[5]);
        }
        else if (i == 57 || i == 61) {
            setMode(EXPLODE);
            countdown->start(timerBoom);
            osc->sendLightSoundCue(cues[6]);
        }
        else if (i == 58) {
            setMode(EXPLODE);
            countdown->start(timerGameOver + timerAgain);
            osc->sendLightSoundCue(cues[7]);
        }
        else if (i == 62) {
            countdown->start(17 /*timerGameOver + timerTired + timerNext*/);
            osc->sendLightSoundCue(cues[8]);
        }
    }
    
    // LED title
    if (isSlave()) {
        if ( i>50 && i<57 ) {
            led->show(title.get());
        }
        else if ( i>58 && i<61 ) {
            led->hide();
        }
        else if (i == 57 || i == 61) {
            led->show(boom.get());
        }
        else if (i == 58) {
            led->hide();
            led->queue(LedDisplay::Params(gameOver.get(), 0, timerGameOver, 0, false, 0));
            led->queue(LedDisplay::Params(playAgain.get(), 0, timerAgain, 0, false, 0));
            led->playQueue();
        }
        else if (i == 62) {
            led->hide();
            led->queue(LedDisplay::Params(gameOver.get(), 0, 4, 0, false, 0));
            led->queue(LedDisplay::Params(tired.get(), 0, 8, 0, false, 0));
            led->queue(LedDisplay::Params(nextLevel.get(), 0, 5, 0, false, 5));
            led->playQueue();
        }
    }
    SceneBase::play(i);
}

void FlantsScene::stop(){;
    vision->getTracker()->bgLearningTime = revertBgLearn;
    isFirstPlay = true;
    SceneBase::stop();
}

void FlantsScene::setupGui() {
    guiName = "Flants";
    panel.setup(guiName, "settings/flants.xml");
{'fraction_non_alphanumeric': 0.16550324675324676, 'fraction_numerical': 0.016233766233766232, 'mean_word_length': 1.9162130177514793, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 98, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5875754', 'n_tokens_mistral': 3959, 'n_tokens_neox': 3730, 'n_words': 697}