Simple Reactor
int gridWidth = 20;
int gridHeight = 20;
float shapeWidth = 30;
float shapeHeight = 30;
float reactorScaler = .06;
int xOffset;
int yOffset;
PVector reactorPosition;
void setup() {
reactorPosition = new PVector(0, 0);
size(700, 700);
// offset used to center the graphics on the screen
xOffset = floor(width/2-(shapeWidth*gridWidth/2));
yOffset = floor(height/2-(gridHeight*shapeHeight/2));
background(255);
smooth();
};
void draw() {
background(255);
fill(0);
noStroke();
pushMatrix();
translate(xOffset, yOffset);//translate matrix to center
for (int i = 0; i<gridWidth; i++ ) {
for (int j = 0; j<gridHeight; j++ ) {
PVector myPos = new PVector(i*shapeWidth, j*shapeHeight);
float reactorDistance = dist(reactorPosition.x, reactorPosition.y, myPos.x, myPos.y);
float scaler = reactorDistance*reactorScaler;
ellipse(myPos.x, myPos.y, 1*scaler, 1*scaler);
};
};
popMatrix();
};
int mouse_X() {
return (mouseX - xOffset); //correct positions after matrix translations
}
int mouse_Y() {
return (mouseY - xOffset); //correct positions after matrix translations
}
void mouseMoved() {
reactorPosition.x = mouse_X();
reactorPosition.y = mouse_Y();
};
, multiple selections available,
