import java.util.Arrays; static Snippet[] snippets; static int numsnippets=1; private static int[] spaces_x,spaces_y; static int space_x,space_y; void reinit() { snippets=new Snippet[16]; numsnippets=1; for (int i=0;i0) return int(a)+1; else return int(a)-1; } final static float DECOLLIDE_X=0.5, DECOLLIDE_Y=0.6; static boolean decollide() { boolean collide=false; for (int i=0;i0 ? 1 : -1; si.x-=dx>0 ? 1 : -1; sj.y+=dy>0 ? 1 : -1; si.y-=dy>0 ? 1 : -1; si.constrain(); sj.constrain(); } } return collide; } static boolean space_taken(int x0, int y0, int x1, int y1) { for (int i=0;i=s.x && x1<=s.x+s.w && y0>=s.y && y1<=s.y+s.h) { return true; } } return false; } void find_biggest_space() { space_x=-1; space_y=-1; // get all the split poitns for (int i=0;ispace_area) { space_x=(x1+free_minx)/2; space_y=(y1+free_miny)/2; space_area=area; } } } } free_minx=-1; free_miny=-1; for (int x=0;xspace_area) { space_x=(x1+free_minx)/2; space_y=(y1+free_miny)/2; space_area=area; } } } } } void mousePressed() { reinit(); } void draw() { Thread.yield(); background(33); fill(192,192,192); stroke(128,128,128); if (!decollide() && numsnippets