public final class Snippet { int x,y,w,h; public Snippet() { x=(int)random(width/2+width/4); y=(int)random(height/2+width/4); w=(int)(width/8+random(width/2)); h=(int)(height/20+random(height/12)); constrain(); } public boolean overlaps(Snippet o) { return ((x>=o.x && x<=o.x+o.w) || (o.x>=x && o.x<=x+w)) && ((y>=o.y && y<=o.y+o.h) || (o.y>=y && o.y<=y+h)); } public int cx() { return x+w/2;} public int cy() { return y+h/2;} public void render() { rect(x+2,y+2,w-4,h-4); } public void constrain() { if (x<0) x=0; else if (x+w>width) x=width-w; if (y<0) y=0; else if (y+h>height) y=height-h; } }