//Here is the mouse callback function, you will need to use the x, y coordinate intelligently to get the color of the pixel that is clicked on.
//You must have a printf statement here as well that prints out the coordinate and the color from the background image at the location
void myMouse(int button, int state, int x, int y)
{
	//You need to think about the x and y coordinate that you get here and if they are what you expect
	switch (button)
	{
	    case GLUT_LEFT_BUTTON:

		    if(state == GLUT_DOWN)
			{
				getImageColor(image, x, y, &Red, &Green, &Blue);
	
				


				printf(" Screen Click R= %u ",Red);

				printf("G=%u ", Green);

				printf("B=%u ", Blue);
				printf("\n");

				//Do something (this is just example if/else statements and not intended to demonstrate anything)
			}
		break;
	}
}
示例#2
0
bool ofxCirclePacker :: checkCircleImage ( Circle& circle )
{
	float radius = ( circle.bUnderMinRadius ) ? circleRadiusMin : circle.radiusNext;
	
	//-- CHECK CIRCLE IS WITHIN IMAGE BOUNDS.
	
	bool lb = circle.loc.x - ( radius + circleDeathGap ) < circleColorBoundsImageRect.x;
	bool rb = circle.loc.x + ( radius + circleDeathGap ) > circleColorBoundsImageRect.x + circleColorBoundsImageRect.width;
	bool tb = circle.loc.y - ( radius + circleDeathGap ) < circleColorBoundsImageRect.y;
	bool bb = circle.loc.y + ( radius + circleDeathGap ) > circleColorBoundsImageRect.y + circleColorBoundsImageRect.height;
	
	if( lb || rb || tb || bb )
	{
		circle.alive = false;
		
		return false;
	}
	
	//-- CHECK CIRCLE IS WITHIN IMAGE SHAPE.
	
	int cx = (int)( circle.loc.x - ( radius + circleDeathGap ) );
	int cy = (int)( circle.loc.y - ( radius + circleDeathGap ) );
	int cw = (int)( ( radius + circleDeathGap ) * 2 );
	int ch = (int)( ( radius + circleDeathGap ) * 2 );
	
	for( int x=cx; x<=cx+cw; x++ )
	{
		for( int y=cy; y<=cy+ch; y++ )
		{
			int c = getImageColor( x, y, circleColorBoundsImagePixels, circleColorBoundsImageRect );
			
			if( circleColorBounds )
			{
				if( c != circle.color )
				{
					circle.alive = false;
					
					return false;
				}
			}
			
			if( c == circleDeathColor )
			{
				circle.alive = false;
				
				return false;
			}
		}
	}
	
	return true;
}
示例#3
0
void ofxCirclePacker :: addCircle( int color )
{
	circles.push_back( Circle() );
	Circle& circle = circles.back();
	
	circle.id				= circleIdCount;
	circle.loc.x			= ofRandom( (float)circleColorBoundsImageRect.x, (float)( circleColorBoundsImageRect.x + circleColorBoundsImageRect.width  ) );
	circle.loc.y			= ofRandom( (float)circleColorBoundsImageRect.y, (float)( circleColorBoundsImageRect.y + circleColorBoundsImageRect.height ) );
	circle.lifeCount		= 0;
	circle.growth			= ofRandom( 0.1, 0.5 );
	circle.radius			= 0;
	circle.radiusNext		= circle.growth;
	circle.alive			= true;
	circle.bUnderMinRadius	= true;
	
	
	if( useCircleColorMapImage )
	{
		circle.color	= getImageColor( (int)circle.loc.x, (int)circle.loc.y, circleColorMapImagePixels, circleColorMapImageRect );
	}
	else
	{
		circle.color	= color;
	}
	
	bool bValid;
	bValid = true;
	
	if( useCircleColorBoundsImage )
	{
		bValid = bValid && checkCircleImage( circle );					// fits on image.
	}
	
	if( bValid )
	{
		bValid = bValid && !checkCircleCollisionWithAll( circle );		// no collision.
	}
	
	if( bValid )									// circle is valid on first pass.
	{
		++circleIdCount;
		
		findNeighbours( circle );					// circle fits, find neighbours.
	}
	else											
	{
		circles.erase( circles.end() - 1 );			// did not fit, remove.
	}
}