Hey, so I'm making just a very basic (and not particularly realistic!) particle simulation. The idea is I want to add a much larger 'particle' i.e. one big circle which again moves randomly around. The way I stop the little particles colliding so far is using booleans and so I was wondering how I could set all the pixels within the larger circle to 'true' using what I already have. Any help would be much appreciated!
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <sstream>
#include <vector>
#include "Graphics.hpp"
Graphics *gfx;
std::vector<int> x_disp;
std::vector<int> y_disp;
int n_particles=1000;
int width=800;
int height=600;
std::vector<bool> look_up(width*height,false);
void draw_pixels() {
gfx->clearScreen(gfx->BLACK);
for (int i=0; i<n_particles; i++) {
gfx->setPixel(x_disp[i],y_disp[i],gfx->WHITE);
}
gfx->flipScreen();
}
int main() {
srand(time(NULL));
// initialise graphics
gfx=new Graphics();
gfx->init(width,height);
bool closed=false;
SDL_Event event;
// set initial positions
for (int i=0; i<n_particles; i++) {
x_disp.push_back(rand()%800);
y_disp.push_back(rand()%600);
look_up[x_disp[i]*y_disp[i]]=true;
// set relevant index in the lookup array to true
}
//int rr = 20;
//gfx->circle(x_circle, y_circle, rr, gfx->GREEN); //Here is where I want to make a circle where all the pixels contained within are set to true
// so that the other little pixel 'particles' don't enter it.
// enter the event loop
while(!closed) {
// small delay
gfx->delay(10);
draw_pixels();
for (int i=0; i<n_particles; i++) {
if (y_disp[i]<0) { //Checks for wrap around
y_disp[i] +=height;
}
if (y_disp[i]>height-1) { //''
y_disp[i] -= height;
}
if (x_disp[i]<0) { //''
x_disp[i] += width;
}
if (x_disp[i] > width-1) { //''
x_disp[i] -= width;
}
}
// update positions
for (int i=0; i<n_particles; i++) {
// choose random direction
int dir=rand()%4;
switch(dir) {
case 0 : // N
if (look_up[x_disp[i]*(y_disp[i]--)]=true) {
break;
}
else {
look_up[x_disp[i]*y_disp[i]]=false;
y_disp[i]--;
look_up[x_disp[i]*y_disp[i]]=true;
break;
}
case 1 : // E
if (look_up[(x_disp[i]++)*y_disp[i]]=true) {
break;
}
else {
look_up[x_disp[i]*y_disp[i]]=false;
x_disp[i]++;
look_up[x_disp[i]*y_disp[i]]=true;
break;
}
case 2 : // S
if (look_up[(x_disp[i])*(y_disp[i]++)]=true) {
break;
}
else {
look_up[x_disp[i]*y_disp[i]]=false;
y_disp[i]++;
look_up[x_disp[i]*y_disp[i]]=true;
break;
}
case 3 : // W
if (look_up[(x_disp[i]--)*(y_disp[i])]=true) {
break;
}
else {
look_up[x_disp[i]*y_disp[i]]=false;
x_disp[i]--;
look_up[x_disp[i]*y_disp[i]]=true;
break;
}
}
}
while(SDL_PollEvent(&event)) {
switch (event.type) {
// react to the QUIT event (i.e. closing the window)
case SDL_QUIT:
closed = true;
break;
}
}
}
// clean up graphics
delete gfx;
return 0;
}