-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
64 lines (46 loc) · 1.17 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <SDL.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include "Screen.h"
#include "Swarm.h"
using namespace std;
using namespace partexplode;
int main()
{
//srand(time(NULL));
Screen screen;
if(screen.init() == false)
{
cout << "SDL initialization failed." << endl;
}
Swarm swarm;
while(true)
{
//Update particles
//Draw particles
int elapsed = SDL_GetTicks();
//screen.clear();
swarm.update(elapsed);
unsigned char red = (unsigned char)((1 + sin(elapsed * 0.0001)) * 128);
unsigned char blue = (unsigned char)((1 + sin(elapsed * 0.0002)) * 128);
unsigned char green = (unsigned char)((1 + cos(elapsed * 0.0003)) * 128);
const Particle * const pParticle = swarm.getParticle();
for(int i=0; i < Swarm::NPARTICLES; i++)
{
Particle particle = pParticle[i];
int x = particle.m_x + Screen::SCREEN_WIDTH/2;
int y = particle.m_y + Screen::SCREEN_HEIGHT/2;
screen.setPixel(x, y, red, blue, green);
}
screen.boxBlur();
//Draw the screen
screen.update();
//Check for messages and events
if(screen.processEvents() == false)
break;
}
screen.close();
return 0;
}