import com.automatous_monk.seurat.ca.BriansBrain; import com.automatous_monk.seurat.ca.CyclicSpace; import com.automatous_monk.seurat.ca.Life; import com.automatous_monk.seurat.ca.Seeds; import com.automatous_monk.seurat.ca.convolution.CADirectConvolution; import com.automatous_monk.seurat.ca.TwoDCellularAutomaton; import com.automatous_monk.seurat.ca.convolution.CAConvolution; import controlP5.ControlP5; import controlP5.Radio; int CYCLIC_SPACE_ID = 0; int LIFE_ID = 2; int SEEDS_ID = 4; int BRIANS_BRAIN_ID = 3; PImage img; PImage edgeImg; TwoDCellularAutomaton cellularAutomaton; CAConvolution cAConvolution; ControlP5 controlP5; void setup() { int myColorBackground = color(0, 0, 0); background(myColorBackground); img = loadImage("VanGogh_TwoCutSunflowers.jpg"); final int radioWidth = 100; size(img.width + radioWidth, img.height); frameRate(8); img.loadPixels(); edgeImg = createImage(img.width, img.height, RGB); createCellularAutomaton(); cAConvolution = new CADirectConvolution(cellularAutomaton, img); controlP5 = new ControlP5(this); Radio r = controlP5.addRadio("radio", img.width, 0); r.addItem("Life", LIFE_ID); r.addItem("Cyclic Space", CYCLIC_SPACE_ID); r.addItem("Brian's Brain", BRIANS_BRAIN_ID); r.addItem("Seeds", SEEDS_ID); } public void draw() { for (int y = 1; y < img.height - 1; y++) { for (int x = 1; x < img.width - 1; x++) { int state = cellularAutomaton.getState(y, x); int pos = y * img.width + x; int pixel = img.pixels[pos]; int c = cAConvolution.convolve(y, x, state, pixel); edgeImg.pixels[pos] = c; } } edgeImg.updatePixels(); image(edgeImg, 0, 0); cellularAutomaton.update(); } void radio(int theID) { if (theID == CYCLIC_SPACE_ID) { cellularAutomaton = new CyclicSpace(img.height, img.width, CyclicSpace.DEFAULT_N); } else if (theID == LIFE_ID) { cellularAutomaton = new Life(img.height, img.width); } else if (theID == SEEDS_ID) { cellularAutomaton = new Seeds(img.height, img.width); } else if (theID == BRIANS_BRAIN_ID) { cellularAutomaton = new BriansBrain(img.height, img.width); } cAConvolution = new CADirectConvolution(cellularAutomaton, img); } void createCellularAutomaton() { cellularAutomaton = new CyclicSpace(img.height, img.width, CyclicSpace.DEFAULT_N); }