// renders a grid of particles by drawing solid color rectangles centered on each Particle's position class PSGRColorCubes implements ParticleSpringGridRenderer, ColorGridRenderer { private ColorGrid cg; private float r; private boolean border, select; private int srow, scol; private color bc; PSGRColorCubes(ColorGrid cg, float r, color borderColor) { this.cg = cg; this.r = r; border = select = true; srow = scol = 0; bc = borderColor; } void showBorder(boolean show) { border = show; } void showSelection(boolean show) { select = show; } void setSelection(int row, int col) { srow = row; scol = col; } ColorGrid getColorGrid() { return cg; } void setColorGrid(ColorGrid cg) { this.cg = cg; } void draw(float x, float y) { noFill(); if ( border ) { stroke(bc); } else { stroke(bc, 128); } rect(x, y, cg.cols()*r + 10, cg.rows()*r + 10); noStroke(); } void draw(Particle fixed, Particle p, int row, int col) { if ( p != null && !p.isDead() ) { color c = cg.get(row, col); if ( row == srow && col == scol && select ) { fill(c); } else { fill(c, 200); } pushMatrix(); translate(p.position().x(), p.position().y(), p.position().z()); box(r); popMatrix(); } } }