Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ofApp.h"
- //--------------------------------------------------------------
- void ofApp::setup(){
- ofSetVerticalSync(true);
- numMesh = 3;
- mesh.addVertex(ofVec3f(-150,0));
- mesh.addColor(ofColor(0));
- mesh.addVertex(ofVec3f(150,0));
- mesh.addColor(ofColor(0));
- mesh.addVertex(ofVec3f(150,100));
- mesh.addColor(ofColor(0));
- mesh.setMode(OF_PRIMITIVE_POINTS);
- }
- //--------------------------------------------------------------
- void ofApp::update(){
- if(braid.size()>0){
- for(int i=0;i<braid.size();i++){
- for(int j=0;j<braid[i].size();j++){
- braid[i][j].update();
- braid[i].erase(
- std::remove_if(braid[i].begin(), braid[i].end(),
- [](const oscThread & o) { return o.dead; }),
- braid[i].end());
- }
- }
- }
- }
- //--------------------------------------------------------------
- void ofApp::draw(){
- ofEnableDepthTest();
- ofEnableAlphaBlending();
- ofBackground(178,29,0);
- cam.begin();
- if(braid.size()>0){
- for(int i=0;i<braid.size();i++){
- for(int j=0;j<braid[i].size();j++){
- braid[i][j].draw();
- }
- }
- }
- cam.end();
- if(outputImg == true){
- img.grabScreen(0,0,ofGetWidth(),ofGetHeight());
- frameCounter++;
- string fileName = ofToString(shotCounter)+"_"+ofToString(frameCounter)+".png";
- img.save(fileName);
- }
- ofDrawBitmapString("Number of Braids: " + ofToString(braid.size()),10,10);
- }
- //--------------------------------------------------------------
- void ofApp::keyPressed(int key){
- if(key=='f'){
- vector<oscThread> tempBraid;
- ofVec2f tempOrigin;
- tempOrigin.set(2,0);
- while (tempOrigin.x == tempOrigin.y){
- tempOrigin.set((int)ofRandom(numMesh),(int)ofRandom(numMesh));
- }
- for(int i=0;i<1;i++){
- tempBraid.push_back(oscThread(tempOrigin,mesh));
- tempBraid.back().setup();
- }
- braid.push_back(tempBraid);
- }
- if(key=='b'){
- outputImg = true;
- }
- }
- //--------------------------------------------------------------
- void ofApp::keyReleased(int key){
- if(key=='b'){
- outputImg = false;
- shotCounter++;
- frameCounter = 0;
- }
- }
- //--------------------------------------------------------------
- void ofApp::gotMessage(ofMessage msg){
- }
- //--------------------------------------------------------------
- void ofApp::dragEvent(ofDragInfo dragInfo){
- }
Add Comment
Please, Sign In to add comment