/** *

To reset display, make sure the applet is active (by clicking on it), and press SPACEBAR.

* * @author Mike Creighton * @version 1.0 2006/10/02 */ // import QuickGrab.*; // Grab grab; // Noise-related variables float yOffset, cOffset, expandOffset; static float Y_INC = 0.04; static float C_INC = 0.03; static float EXPAND_INC = 0.04; static int NUM_COLORS = 6; color[] colorArray = new color[NUM_COLORS]; color bgColor; PImage cap, out; int halfWidth; void setup() { size(400, 300, P3D); halfWidth = width / 2; frameRate(30); // grab = new Grab(this); // Create our image buffers cap = createImage(width / 2, height, RGB); out = createImage(width / 2, height, RGB); resetDisplay(); } void draw() { noiseDetail(3); float yNoise = noise(yOffset); noiseDetail(1); float cNoise = noise(cOffset); float expandNoise = noise(expandOffset); // Get a color to use for our pen. int whichColor = floor(cNoise * (NUM_COLORS - 1)); stroke(colorArray[whichColor], 64); int yPos = floor(yNoise * height * 2 - (height/2)); point(halfWidth, yPos); // Bleeding algorithm // blend(HALF_W, 0, HALF_W - 1, height, HALF_W + 1, 0, HALF_W - 1, height, BLEND); // Breathing algorithm blend(halfWidth, 0, halfWidth, height, halfWidth + parseInt(expandNoise * 70), 0, halfWidth, height, BLEND); // Grab what's on the right half of the canvas // Note: variable "g" is the current PImage representing the output on the screen cap.copy(g, width / 2, 0, cap.width, cap.height, 0, 0, cap.width, cap.height); // Loop through all the pixels, but flip them horizontally int widthCounter = 0; for(int i = cap.width - 1; i >= 0; i--){ for(int j = 0; j < cap.height; j++){ out.pixels[i + j * cap.width] = cap.pixels[widthCounter + j * cap.width]; } widthCounter++; } copy(out, 0, 0, cap.width, cap.height, 0, 0, cap.width, cap.height); yOffset += Y_INC; cOffset += C_INC; expandOffset += EXPAND_INC; // Make sure we don't break the noise() method. Reset these once they get too high. if(yOffset > 9999) yOffset = 0.0; if(cOffset > 9999) cOffset = 0.0; if(expandOffset > 9999) expandOffset = 0.0; } void keyReleased() { if (keyCode == 32) { // Reset display on SPACEBAR press resetDisplay(); } } private void resetDisplay() { yOffset = random(99); cOffset = random(99); expandOffset = random(99); // Choose five random colors. for (int i = 0; i < NUM_COLORS; i++){ int[] rgbArray = new int[3]; for (int j = 0; j < 3; j++){ rgbArray[j] = floor(random(255)); } colorArray[i] = color(rgbArray[0],rgbArray[1],rgbArray[2]); } bgColor = colorArray[NUM_COLORS - 1]; background(red(bgColor), green(bgColor), blue(bgColor)); }