(n)certainties

GSAPP-Fall 2011

(n)certainties header image 3

reaction-diffusion

/**
*

CustomGrayScott shows how to extend the GrayScott class to create spatial
* differences in behaviour (i.e. different patterns) through manipulating the
* F and K coefficients of the reaction diffusion. The demo also uses the
* ColorGradient & ToneMap classes of the colorutils package to create a
* tone map for rendering the results of the Gray-Scott reaction-diffusion.

*
*

Usage:

      *

    • click + drag mouse to draw dots used as simulation seed

*

*/
import toxi.sim.grayscott.*;
import toxi.math.*;
import toxi.color.*;
import toxi.geom.*;
import controlP5.*;
ControlP5 chemControl;
ControlWindow controlWindow;
//float f_Value = 0.025;
float f_Value = 0.029;
float k_Value = 0.074;
float dU_Value = 0.21;
float dV_Value = 0.05;

int NUM_ITERATIONS = 10;

GrayScott gs;
ToneMap toneMap;
PImage img;

void setup() {
size(900, 700);
smooth();
//initialize Controllers
chemControl = new ControlP5(this);
controlWindow = chemControl.addControlWindow(“controlP5window”, 100, 100, 300, 200);
controlWindow.setBackground(color(0));
//slider values (“name”, min value, max value, default, x, y, width, height)
Controller mySlider_f = chemControl.addSlider(“f_Value”, 0.001, 0.07, 1, 20, 200, 10);
Controller mySlider_k = chemControl.addSlider(“k_Value”, 0.05, 0.3, 1, 40, 200, 10);
Controller mySlider_dU = chemControl.addSlider(“dU_Value”, 0.01, 0.3, 1, 60, 200, 10);
Controller mySlider_dV = chemControl.addSlider(“dV_Value”, 0.001, 0.25, 1, 80, 200, 10);
mySlider_f.setWindow(controlWindow);
mySlider_k.setWindow(controlWindow);
mySlider_dU.setWindow(controlWindow);
mySlider_dV.setWindow(controlWindow);
controlWindow.setTitle(“chemical_control”);
chemControl.setAutoDraw(true);

gs=new PatternedGrayScott(width, height, false); //does RD wrap in applet or not (true or false)
img=loadImage(“900x700smsmall.png”); //loads image//image must be in data file and greyscale negative of what you want to appear

//gs.setCoefficients(0.021, 0.077, 0.1, 0.05); //3rd = dots or stripes, 4th = lifetime (.062) (this is commented out for sliders, coefficients controlled in the global variables or within slider)
// create a color gradient for 256 values
ColorGradient grad=new ColorGradient();
grad.addColorAt(0, NamedColor.WHITE); // BACKGROUND COLOR
//grad.addColorAt(100, NamedColor.WHITE);
grad.addColorAt(255, NamedColor.BLACK); // COLOR OF ‘REACTION’
// setting the max = 0.33 increases the contrast
toneMap=new ToneMap(0, .33, grad);
}

void draw() {
gs.setCoefficients(f_Value, k_Value, dU_Value, dV_Value); //lets sliders draw
if (mousePressed) {
gs.setRect(mouseX, mouseY, 50,50);
}
gs.seedImage(img.pixels, img.width, img.height); // draws image
loadPixels();
// update the simulation a few time steps
for (int i=0; i gs.update(1);
}

// read out the V result array and use tone map to render colours
for (int i=0; i pixels[i]=toneMap.getARGBToneFor(gs.v[i]);
}
updatePixels();
saveFrame(“Core_111128_11/frames-####.png”);
}

void keyPressed() {
gs.reset();
}

class PatternedGrayScott extends GrayScott {
public PatternedGrayScott(int w, int h, boolean tiling) {
super(w, h, tiling);
}
public float getFCoeffAt(int x, int y) {
float myDistance = dist(width/2, height/2, x, y) ;
//return f-x*.00004;
return f-myDistance*.0001;
}
// public float getKCoeffAt(int x, int y) {
// float myDistance = dist(width/2, height/2, x, y) ;
// //return f-x*.00004;
// return k-myDistance*.0000001;
// }
}