// random rect inside outer with any size (0*0 to full width/height) static Rect randomRect(Rect outer) { var w = random_incl(outer.w); var h = random_incl(outer.h); ret randomRect(w, h, outer); } static Rect randomRect(int w, int h, Rect outer) { ret translateRect(outer.x, outer.y, randomRect(outer.w, outer.h, 0, w, h)); } static Rect randomRect(Rect outer, int w, int h) { ret randomRect(w, h, outer); } static Rect randomRect(int w, int h, int border default 0, int rw, int rh) { if (rw > w-border*2 || rh > h-border*2) null; int ww = random(border, w-border-rw); int hh = random(border, h-border-rh); ret new Rect(ww, hh, rw, rh); } static Rect randomRect(int w, int h) { // making variables to ensure functions are called in the same order every time int rw = random(w); int rh = random(h); ret randomRect(w, h, 0, rw, rh); } ifclass RGBImage static Rect randomRect(RGBImage img, int rw, int rh) { ret randomRect(img.w(), img.h(), 0, rw, rh); } static Rect randomRect(RGBImage img) { ret randomRect(img.w(), img.h()); } endif // on currentImage() static Rect randomRect() { ret randomRect(currentImage().getWidth(), currentImage().getHeight()); } static Rect randomRect(BufferedImage img, int rw, int rh) { ret randomRect(img.getWidth(), img.getHeight(), 0, rw, rh); }