// Author: Paul Reiners import com.automatous_monk.seurat.ca.TwoDCellularAutomaton; import com.automatous_monk.seurat.ca.convolution.CAConvolution; import controlP5.ControlP5; import com.automatous_monk.seurat.ca.BriansBrain; import com.automatous_monk.seurat.ca.convolution.CAWeightedConvolution; import controlP5.ControlP5; import controlP5.Radio; PImage img; PImage edgeImg; TwoDCellularAutomaton cellularAutomaton; CAConvolution cAConvolution; ControlP5 controlP5; int DEFAULT_CONVOLUTION_INDEX = 1; float[][] kernel = Kernel.kernels[DEFAULT_CONVOLUTION_INDEX]; 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 CAWeightedConvolution(cellularAutomaton, img, kernel); controlP5 = new ControlP5(this); int kernelCount = Kernel.kernels.length; Radio r = controlP5.addRadio("radio", img.width, 0); for (int i = 0; i < kernelCount; i++) { r.addItem("Convolution " + i, i); } r.setId(DEFAULT_CONVOLUTION_INDEX); r.activate("Convolution " + DEFAULT_CONVOLUTION_INDEX); } void radio(int theID) { kernel = Kernel.kernels[theID]; cAConvolution = new CAWeightedConvolution(cellularAutomaton, img, kernel); } protected void createCellularAutomaton() { cellularAutomaton = new BriansBrain(img.height, img.width); } 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(); }