Can someone please help me see what I can do to improve performance here?
I added this simple loop to draw() portion of a sketch:
ofSetColor( 55, 55, 55, 50);
ofSetLineWidth( 1 );
for(int i = 0; i < ofGetScreenHeight(); i += 10){
for(int j = 0; j < ofGetScreenWidth(); j += 10){
ofLine(j, i, j+value*10, i+value*10);
}
}
As soon as I did that, the sketch has slowed to a crawl. I don’t understand why, since the sketch itself doesn’t have much going on at all. Here is a clip from the setup() through draw() portions:
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofPoint p;
// p = ofPoint( 100.0, 200.0 );
p.x = 100.0;
p.y = 200.0;
ofSetWindowShape( 1024, 768);
stem0 = ofPoint( 700, 100 ); //top
stem1 = ofPoint( 300, 140 ); //upper midpoint
stem2 = ofPoint( 350, 225 ); //lower midpoint
stem3 = ofPoint( 970, 710 ); //bottom
leftLeaf = ofPoint( 400, 520 ); //outer edge
rightLeaf = ofPoint( 600, 420 ); //outer edge
topSide = ofPoint( 50, 50 );
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
//background
float time = ofGetElapsedTimef();
float value = sin( time * M_TWO_PI );
//defaults: map sin wave to -1 & 1, then map that 0 & 255
float v = ofMap( value, -2, 2, 0, 255 );
float vNeg = ofMap( value, -1, 1, 255, 0);
ofBackground( v, v, v );
cout << "v: " << v << "\n";
cout << "v/200: " << v/200 << "\n";
cout << "value: " << value << "\n";
ofSetColor( vNeg, vNeg, vNeg, 200 );
ofFill();
ofSetLineWidth( 1 );
ofSetCircleResolution( 100 );
ofEnableSmoothing();
ofLine( stem0, stem1 + v );
ofLine( stem2 + v, stem3 );
ofTriangle( (stem1 + v)-0.25, (stem2 + v)-0.25, leftLeaf * (v/200) );
ofTriangle( (stem1 + v)+0.25, (stem2 + v)+0.25, rightLeaf * (v/200) );
ofLine( rightLeaf * (v/200) , topSide );
ofLine( leftLeaf * (v/200) , topSide );
ofSetColor( 55, 155, 255);
ofNoFill();
ofCircle( stem0, 1 + ( 10 * (v/200) ) );
ofSetColor( 255, 55, 55);
ofLine( 970, 710, 980, 710 );
ofLine( 970, 710, 960, 710 );
ofLine( 970, 710, 970, 700 );
ofLine( 970, 710, 970, 720 );
ofSetColor( 55, 255, 55);
ofLine( 50, 50, 50, 60 );
ofLine( 50, 50, 50, 40 );
ofLine( 50, 50, 40, 50 );
ofLine( 50, 50, 60, 50 );
ofDrawBitmapStringHighlight( "THE STRUGGLER", 20, ofGetHeight() - 20 );
//ofDrawBitmapString( ofToString(value), 150, 748 );
}