Guest User

Untitled

a guest
Dec 25th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. #include "ofApp.h"
  2.  
  3. //--------------------------------------------------------------
  4. void ofApp::setup(){
  5. ofSetVerticalSync(true);
  6. numMesh = 3;
  7.  
  8. mesh.addVertex(ofVec3f(-150,0));
  9. mesh.addColor(ofColor(0));
  10. mesh.addVertex(ofVec3f(150,0));
  11. mesh.addColor(ofColor(0));
  12. mesh.addVertex(ofVec3f(150,100));
  13. mesh.addColor(ofColor(0));
  14.  
  15. mesh.setMode(OF_PRIMITIVE_POINTS);
  16. }
  17.  
  18. //--------------------------------------------------------------
  19. void ofApp::update(){
  20. if(braid.size()>0){
  21. for(int i=0;i<braid.size();i++){
  22. for(int j=0;j<braid[i].size();j++){
  23. braid[i][j].update();
  24. braid[i].erase(
  25. std::remove_if(braid[i].begin(), braid[i].end(),
  26. [](const oscThread & o) { return o.dead; }),
  27. braid[i].end());
  28. }
  29. }
  30. }
  31. }
  32.  
  33. //--------------------------------------------------------------
  34. void ofApp::draw(){
  35. ofEnableDepthTest();
  36. ofEnableAlphaBlending();
  37. ofBackground(178,29,0);
  38.  
  39. cam.begin();
  40. if(braid.size()>0){
  41. for(int i=0;i<braid.size();i++){
  42. for(int j=0;j<braid[i].size();j++){
  43. braid[i][j].draw();
  44. }
  45. }
  46. }
  47. cam.end();
  48.  
  49. if(outputImg == true){
  50. img.grabScreen(0,0,ofGetWidth(),ofGetHeight());
  51. frameCounter++;
  52. string fileName = ofToString(shotCounter)+"_"+ofToString(frameCounter)+".png";
  53. img.save(fileName);
  54. }
  55.  
  56. ofDrawBitmapString("Number of Braids: " + ofToString(braid.size()),10,10);
  57. }
  58.  
  59. //--------------------------------------------------------------
  60. void ofApp::keyPressed(int key){
  61. if(key=='f'){
  62. vector<oscThread> tempBraid;
  63. ofVec2f tempOrigin;
  64. tempOrigin.set(2,0);
  65.  
  66. while (tempOrigin.x == tempOrigin.y){
  67. tempOrigin.set((int)ofRandom(numMesh),(int)ofRandom(numMesh));
  68. }
  69.  
  70. for(int i=0;i<1;i++){
  71. tempBraid.push_back(oscThread(tempOrigin,mesh));
  72. tempBraid.back().setup();
  73. }
  74.  
  75. braid.push_back(tempBraid);
  76. }
  77.  
  78. if(key=='b'){
  79. outputImg = true;
  80. }
  81. }
  82.  
  83. //--------------------------------------------------------------
  84. void ofApp::keyReleased(int key){
  85. if(key=='b'){
  86. outputImg = false;
  87. shotCounter++;
  88. frameCounter = 0;
  89. }
  90. }
  91.  
  92. //--------------------------------------------------------------
  93. void ofApp::gotMessage(ofMessage msg){
  94.  
  95. }
  96.  
  97. //--------------------------------------------------------------
  98. void ofApp::dragEvent(ofDragInfo dragInfo){
  99.  
  100. }
Add Comment
Please, Sign In to add comment