// renders a grid of particles by drawing solid color rectangles centered on each Particle's position class PSGRColorSquares implements ParticleSpringGridRenderer, ColorGridRenderer { private ColorGrid cg; private float r; private boolean border, select; private int srow, scol; private color bc; private float bw, bh; private color sc; private float scDelt; PSGRColorSquares(ColorGrid cg, float r, color borderColor, float borderWidth, float borderHeight) { this.cg = cg; this.r = r; select = true; border = false; srow = scol = 0; bc = borderColor; bw = borderWidth; bh = borderHeight; sc = ColorGrid.WHITE; scDelt = -20; } 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) { if ( border ) { fill(bc); } else { fill(bc, 128); } noStroke(); rect(x, y, bw, 3); rect(x, y, 3, bh); } void draw(Particle fixed, Particle free, int row, int col) { // free color c = cg.get(row, col); fill(c); stroke(0); pushMatrix(); translate(free.position().x(), free.position().y(), free.position().z()); rect(0, 0, r, r); popMatrix(); if ( row == srow && col == scol ) { tickSelectColor(); stroke(sc); noFill(); pushMatrix(); translate(fixed.position().x(), fixed.position().y(), fixed.position().z()); rect(0, 0, r+1, r+1); popMatrix(); } } private void tickSelectColor() { sc += scDelt; if ( sc < 0 ) { sc = 0; scDelt *= -1; } else if ( sc > 255 ) { sc = 255; scDelt *= -1; } } }