コード例 #1
0
int main() {

	srand(time(NULL));

	Screen screen;

	if (screen.init() == false) {
		cout << "Error initialising SDL." << endl;
	}

	Swarm swarm;

	while (true) {
		// Update particles
		// Draw particles

		int elapsed = SDL_GetTicks();

		screen.clear();
		swarm.update();

		unsigned char green =
				(unsigned char) ((1 + sin(elapsed * 0.0001)) * 128);
		unsigned char red = (unsigned char) ((1 + sin(elapsed * 0.0002)) * 128);
		unsigned char blue = (unsigned char) ((1 + sin(elapsed * 0.0003)) * 128);

		const Particle * const pParticles = swarm.getParticles();

		for (int i = 0; i < Swarm::NPARTICLES; i++) {
			Particle particle = pParticles[i];

			int x = (particle.m_x + 1) * Screen::SCREEN_WIDTH / 2;
			int y = (particle.m_y + 1) * Screen::SCREEN_HEIGHT / 2;

			screen.setPixel(x, y, red, green, blue);
		}

		// Draw the screen
		screen.update();

		// Check for messages/events
		if (screen.processEvents() == false) {
			break;
		}
	}

	screen.close();

	return 0;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: rtkcs/Cpp
int main(){
	Screen screen;

	try{
		srand(time(NULL));


		if(screen.init() == false){
			cout << "Error initialising SDL." << endl;
		}

		Swarm swarm;

		while(true){

			int elapsed = SDL_GetTicks();
			swarm.update(elapsed);

			unsigned char red = (1 + sin(elapsed * 0.0001)) * 128;
			unsigned char green = (1 + sin(elapsed * 0.0002)) * 128;
			unsigned char blue = (1 + sin(elapsed * 0.0003)) * 128;

			const Particle * const pParticles = swarm.getParticles();
			for(int i=0; i<Swarm::NPARTICLES; i++){
				Particle particle = pParticles[i];
				int x = (particle.m_x + 1) * Screen::SCREEN_WIDTH / 2;
				int y = particle.m_y  * Screen::SCREEN_WIDTH / 2 + Screen::SCREEN_HEIGHT / 2;
				screen.setPixel(x, y, red, green, blue);
			}

			screen.boxBlur();

			//draw the screen
			screen.update();

			if(screen.processEvents() == false){
				break;
			}
		}

	} catch(...){
		cout << "exception occured";
	}

	screen.close();
	return 0;

}
コード例 #3
0
int main() {

	srand(time(NULL));

	Screen screen;
	Swarm swarm;

	if (!screen.init()) {
		cout << "Error initializing SDL" << flush;
	}

	while (true) {

		const Particle* const pParticles = swarm.getParticles();

		screen.clear();
		swarm.update();

		int elapsed = SDL_GetTicks();
		unsigned char green = (unsigned char) (1 + sin(elapsed * 0.001) * 128);
		unsigned char red = (unsigned char) (1 + sin(elapsed * 0.002) * 128);
		unsigned char blue = (unsigned char) (1 + sin(elapsed * 0.003) * 128);

//		unsigned char blue = 255;
//		unsigned char red = 255;
//		unsigned char green = 255;

		for (int i = 0; i < Swarm::NPARTICLES; i++) {
			Particle particle = pParticles[i];

			int x = (particle.m_x + 1) * Screen::SCREEN_WIDTH / 2;
			int y = particle.m_y * Screen::SCREEN_WIDTH / 2
					+ Screen::SCREEN_HEIGHT / 2;

			screen.setPixel(x, y, red, green, blue);
		}

		screen.screenUpdate();

		if (!screen.processEvents()) {
			break;
		}
	}

	screen.close();

	return 0;
}
コード例 #4
0
int main() {

	srand(time(NULL));

	Screen screen;
	screen.init();

	Swarm swarm;

	int halfWidth = screen.width() / 2;
	int halfHeight = screen.height() / 2;

	while (true) {

		swarm.update(SDL_GetTicks());

		const Particle * const pParticles = swarm.particles();

		for (int i = 0; i < swarm.size(); i++) {
			int x = pParticles[i].x() * halfWidth + halfWidth;
			int y = pParticles[i].y() * halfWidth + halfHeight;

			screen.setPixel(x, y, pParticles[i].red(), pParticles[i].green(),
					pParticles[i].blue());
		}

		screen.boxBlur();
		screen.update();

		if (!screen.processEvents()) {
			break;
		}
	}

	screen.close();

	return 0;
}