[SOLVED] Flickering around.

Hello my friends

I have a small beginners question. I found an awesome book for P55 and I decided to learn oF with help of that book. I allready have big problems doing the first example because they use HSV colors … Since I couldn’t get a decent HSV to RGB conversion running I just dabble with HEX values.

I works quite fine but it flickers like hell. Since I’m new with c++ I wanted to ask what is wrong with my code which follows right here :smiley:

  
  
//--------------------------------------------------------------  
void testApp::update(){  
	int hexColor = 0xFFFFFF / ofGetWidth() * mouseX;  
  
	r = (hexColor & 0xFF0000) >> 16;  
	g = (hexColor & 0x00FF00) >> 8;  
	b = hexColor & 0x0000FF;  
  
	ofBackground(r, g, b);  
  
	int antiHexColor = 0xFFFFFF - hexColor;  
  
	antiR = (antiHexColor & 0xFF0000) >> 16;  
	antiG = (antiHexColor & 0x00FF00) >> 8;  
	antiB = antiHexColor & 0x0000FF;  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
	ofSetRectMode( OF_RECTMODE_CENTER );  
	ofSetColor(antiR, antiG, antiB);  
	ofRect( ofGetWidth() / 2, ofGetHeight() / 2, ofGetHeight() - mouseY, ofGetHeight() - mouseY );  
}  
  

Thanks in advance for any help and comment.

yours, a

I copied the function from here: http://www.gamedev.net/topic/353603-problem-converting-hsl-to-rgb-solved/ which workes quite nice for me.

  
  
//--------------------------------------------------------------  
void testApp::ibaSetColorHSV(double h, double s, double l){  
	double r, g, b;  
	double temp1, temp2, temp3, tempr, tempg, tempb;  
  
	h /= 360.0;  
	s /= 256.0;  
	l /= 256.0;  
  
	if(s == 0){  
		r = g = b = l;  
	} else {  
		if(l < 0.5)  
			temp2 = l * (1.0 + s);  
		else  
			temp2 = (l + s) - (l * s);  
  
		temp1 = 2.0 * l - temp2;  
		tempr = h + 1.0 / 3.0;  
  
		if(tempr > 1.0)  
			tempr -= 1.0;  
  
		tempg = h;  
		tempb = h - 1.0 / 3.0;  
  
		if(tempb < 0)  
			tempb += 1.0;  
  
		if(6.0 * tempr < 1.0){  
			r = temp1 + (temp2 - temp1) * 6.0 * tempr;  
		} else if(2.0 * tempr < 1.0){  
			r = temp2;  
		} else if(3.0 * tempr < 2.0){  
			r = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - tempr) * 6.0;  
		} else {  
			r = temp1;  
		}  
  
		if(6.0 * tempg < 1.0){  
			g = temp1 + (temp2 - temp1) * 6.0 * tempg;  
		} else if(2.0 * tempg < 1.0){  
			g = temp2;  
		} else if(3.0 * tempg < 2.0){  
			g = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - tempg) * 6.0;  
		} else {  
			g = temp1;  
		}  
  
		if(6.0 * tempb < 1.0){  
			b = temp1 + (temp2 - temp1) * 6.0 * tempb;  
		} else if(2.0 * tempb < 1.0){  
			b = temp2;  
		} else if(3.0 * tempb < 2.0){  
			b = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - tempb) * 6.0;  
		} else {  
			b = temp1;  
		}  
  
		ofSetColor(r * 256.0, g * 256.0, b * 256.0);  
	}  
}  
  

hi!

if you are on OF007 you can use the shiny new ofColor methods!
look here: https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/types/ofColor.h
or a little example here: http://forum.openframeworks.cc/t/tween-color-gradient-over-time/6756/2

ben

Hell yeah benben - you’re my man :slight_smile:

Grüsse an den Osten aus dem Osten …