/** *

This class is to store information about segments of an image so * they can be processed in some sort of order easy going, relaxed, order. */ /** *

The segments class is a collection of segments, each which represents a rectangular area of an image. * Each segment has four basic integer properties, x,y coordinates, width and height. A segment may also contain * the portion of the image that it represents stored as a PImage. The segments class has methods for returning * the next segment of an image, useful if using an image processing loop and you want to keep track of which * segment of the image last dealt with. Built specifically for rendering a large image in small sections. * NB: The second constructor takes in a PImage and breaks it down into segments by the specified cols and rows. * The first constructor is a general purpose one that simply requires a maximum number of segments. */ class segments { private segment[] segs; private int count; int last; segments(int size) { segs = new segment[size]; count = 0; last = -1; } segments(PImage image, int cols, int rows) { segs = new segment[cols*rows]; int segWidth = image.width/cols; int segHeight = image.height/rows; int count = 0; for(int r=0; r= count) { last = -1; return null; } return segs[last]; } segment current() { return segs[last]; } // Will return the previous element until it reaches the beginning segment previous() { if(--last < 0) { last = count; return null; } return segs[last]; } } class segment { PImage image; int width, height; int x, y; segment(int x, int y, int width, int height) { this.image = null; this.x = x; this.y = y; this.width = width; this.height = height; } segment(PImage image, int x, int y) { this.image = image; this.x = x; this.y = y; this.width = image.width; this.height = image.height; } }