Пример #1
0
void WisteriaApp::update()
{
	// Iterate all the blossoms, update each one and notice if they are all idle
	bool isIdle = true;
	for( vector<Branch>::iterator blossomIt = mBlossoms.begin(); blossomIt != mBlossoms.end(); ++blossomIt ) {
		blossomIt->update();
		if( blossomIt->isAlive() )
			isIdle = false;
	}

	if( isIdle && ( ! mIsIdle ) ) {
		mIsIdle = true;  // first frame of idleness
		mIdleFrames = 0;
	}
	else if( isIdle ) { // the blossoms have all not changed in a while, let's clear them out and put up some new ones
		if( mIdleFrames++ > IDLE_RESTART_FRAMES ) {
			// clear the context
			mOffscreenContext.setSourceRgb( 0.23f, 0.23f, 0.23f );
			mOffscreenContext.paint();
			
			mBlossoms.clear();
			mBlossoms.push_back( Branch( Vec2f( Rand::randFloat( WIDTH ), Rand::randFloat( HEIGHT ) ), Branch::randomHue(), 0 ) );
			mBlossoms.push_back( Branch( Vec2f( Rand::randFloat( WIDTH ), Rand::randFloat( HEIGHT ) ), Branch::randomHue(), 180 ) );
			mBlossoms.push_back( Branch( Vec2f( Rand::randFloat( WIDTH ), Rand::randFloat( HEIGHT ) ), Branch::randomHue(), 320 ) );
			
			mIsIdle = false;
		}
	}
}
Пример #2
0
void CairoBasicApp::renderScene( cairo::Context &ctx )
{
	// clear the context with our radial gradient
	cairo::GradientRadial radialGrad( getWindowCenter(), 0, getWindowCenter(), getWindowWidth() );
	radialGrad.addColorStop( 0, Color( 1, 1, 1 ) );
	radialGrad.addColorStop( 1, Color( 0.6, 0.6, 0.6 ) );	
	ctx.setSource( radialGrad );	
	ctx.paint();
	
	for( vector<Flower>::const_iterator flIt = mFlowers.begin(); flIt != mFlowers.end(); ++flIt )
		flIt->draw( ctx );
}
Пример #3
0
void WisteriaApp::setup()
{
	// allocate our offscreen buffer
	mOffscreenBuffer = cairo::SurfaceImage( WIDTH, HEIGHT, false );
	mOffscreenContext = cairo::Context( mOffscreenBuffer );

	// fill the buffer with gray
	mOffscreenContext.setSourceRgb( 0.23f, 0.23f, 0.23f );
	mOffscreenContext.paint();
	
	// Let the Branches know how big our windows is
	Branch::setWindowSize( WIDTH, HEIGHT );
	
	// Create some starting blossoms
	mBlossoms.push_back( Branch( Vec2f( WIDTH - 50, 50 ), 0.619444444f, 0 ) );
	mBlossoms.push_back( Branch( Vec2f( 60, HEIGHT - 60 ), 0.905f, 180 ) );
	mBlossoms.push_back( Branch( Vec2f( WIDTH / 2, HEIGHT / 2 ), 0.105555556f, 320 ) );
	
	mIsIdle = false;
	mIdleFrames = 0;
}