Need help for connecting controlP5 and Custom gray scott
in
Contributed Library Questions
•
8 months ago
Hello all. I'm new at Processing.
I have been struggling to connect controlP5 and Custom gray scott which I got from open source library. Currently, I'm interested in introducing Reaction-diffusion simulation that used pollutant concentration as a starting condition of my project.
I would appreciate if someone would be able to explain a reason why the below link does not work well, that would be wonderful. I believe it works well without ControlP5 connection and don't need image attachment to sort it out this inquiry.
Thank you to anyone who is willing to help.
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;
// }
}
1