Optimisation

I’m trying to reproduce the brush “web” from this web app http://www.chromeexperiments.com/detail/harmony/ in an open framework app.

I have manage to create the same result. My problem is that my app is really slow. After few seconds of painting my brush stop being real time. JS + HTML5 is good but my guess is C++ is suppose to be way more powerful! :wink:

I’m new to C++. Here’s part of my code… At first I used simple vector to store mouse coord points, than I tried to use a pointer in my vector to gain performance… not much change.

Do you have any idea of how I could optimise my app?

testApp.ccp :

  
  
#include "testApp.h"  
  
  
  
//--------------------------------------------------------------  
void testApp::setup(){  
	  
	franklin.loadFont("frabk.ttf",12);  
	ofBackground(255, 255, 255);  
	start = TRUE;  
  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
  
	  
	ofEnableSmoothing();  
	int test;  
	for(int i=1;i<points.size();i++){  
			  
		ofSetColor(0, 0, 0);  
		if (!points[i]->start) {  
			ofLine(points[i-1]->x, points[i-1]->y, points[i]->x, points[i]->y);  
			test = points[i]->x;  
		}  
		  
	}  
	  
  
	ofEnableAlphaBlending();  
	  
	for(int i=1;i<sideLines.size();i++){  
		  
		ofSetColor(sideLines[i]->colorR, sideLines[i]->colorG, sideLines[i]->colorB, sideLines[i]->transparency);  
		ofLine(sideLines[i]->x1, sideLines[i]->y1, sideLines[i]->x2, sideLines[i]->y2);  
		  
	}  
  
	ofDisableAlphaBlending();  
	  
	  
	sprintf(eventString, "Size: %i | X: %i",points.size(),test);  
	franklin.drawString(eventString, 50,50);  
	  
	  
}  
  
//--------------------------------------------------------------  
void testApp::keyPressed(int key){  
	  
	if(key == 'p') {  
	points.clear();  
	}  
	if (key == 's') {  
	sideLines.clear();  
	}  
  
}  
  
  
//--------------------------------------------------------------  
void testApp::mouseDragged(int x, int y, int button){  
  
  
	points.push_back(new point(x,y,start));  
	  
	if(!start)  {	  
	  
		for(int i=0;i<points.size();i++){  
		  
			if ((x-points[i]->x)*(x-points[i]->x)+(y-points[i]->y)*(y-points[i]->y) < 4500 && ofRandomuf() > 0.90)	{  
	  
			  
				sideLines.push_back(new sideLine(ofRandom(1,150),x,y,points[i]->x,points[i]->y));  
			  
			}  
		  
		}  
	}  
	  
	start = FALSE;  
	  
}  
  
  
//--------------------------------------------------------------  
void testApp::mouseReleased(int x, int y, int button){  
	  
	start = TRUE;  
	  
}  
  
  
  
  

I have two vectors.

One (points) keeps coordinates(x,y) from the mouse on mouseDragged.

The other one (sideLines) keep tracks of lines created between points of the mouse trajectory.

I then on testApp::draw() , draw lines between the points of the points vector and draw lines from the sideLine vector.

It would realy help me if someone could names an optimization technic related to this so I could explore some documentation. Cause for now I have no clue … :frowning:

i think the problem is that you have to draw every line you ever made.
that means if you draw a little bit the number of lines to draw increases rapidly.

you can think of something like that:
everytime the mouse is released (which means the drawing is finished) then take the whole screen and make a picture from it (i think about something like that: http://www.openframeworks.cc/documentat-…-grabScreen). then you clear the whole screen and use the image as background for your new drawing.

ben

My goal for this project is to create a drawing tool that react to the ambient sound. So it need to be real time.

Your solution wouldn’t fit, but tks for your time. I should have specify it first.

Commenting ofEnableSmoothing(); solve my problem. And i find the ting more beautiful.