Draw if you want a different shape, 'space' to reset with an "A", 'r' to reset with your shape, 'b' to use a black background, 'k' to toggle colors off, 's' to save locally, wheel to control the 'speed' of the graph...
A fork of Reaction Diffusion - Webgl2 by Pierre MARZIN
xxxxxxxxxx
//vizualization of my "art" functions
//ported to P5JS from a sketch by Pierre MARZIN 12/10/2014
//number of pixels
var nbpix;
//width, height, center (cx,cy)
var w, h, cx, cy;
//flags
//are we using our own doodle
var drawn = false;
//are we drawing
var drawing=false;
//one cycle= one function, one color
var cycles;
var ncycles;
//pimg is the layer where we draw the base points
var pimg;
//different parameters affecting the functions
var m, flou, m1, m2, m3, mt1, mt2, mt3, t0, t1, t2, t3, f0, f1, f2, f3, epsilon;
// artCurves settings
var acDef = {
name : 'Art curves',
hue : 200, //base tint(0-->360)
max_hue_offset : 30,//
ncycles:2,//how many functions
symmetry:true,//are the symmetric curves/Oy drawn?
black_background:false,//black or white background
blackandwhite:false,
save:saveImage,
functions_variation:.2,
randomize: initiate,
sign: initpimg
};
//controller for the black_background tick box
var background_controller;
var gui;
function setup() {
pixelDensity(1);
createCanvas(windowWidth, windowHeight);
w = width;
h = height;
cx=w*.5;
cy=h*.5;
colorMode(HSB, 360, 255, 255, 255);
cycles = [];
nbpix = w * h;
// create gui (dat.gui)
gui = new dat.GUI();
gui.add(acDef, 'name');
gui.add(acDef, 'hue' , 0, 360 ).listen();
gui.add(acDef, 'ncycles' , 1, 5 ).step(1).listen();
gui.add(acDef, 'max_hue_offset' , 0, 180 ).listen();
gui.add(acDef, 'symmetry' ).listen();
var controller = gui.add(acDef, 'black_background').listen();
controller.onFinishChange(function(value) {initiate();});
var controllerbw = gui.add(acDef, 'blackandwhite' ).listen();
controllerbw.onFinishChange(function(value) {initiate();});
gui.add(acDef,'save');
var controllerfv = gui.add(acDef, 'functions_variation',.1,.8 ).listen();
controllerfv.onFinishChange(function(value) {initiate();});
gui.add(acDef,'randomize');
var controllerA = gui.add(acDef, 'sign').listen();
controllerA.onFinishChange(function(value) {initpimg();initiate();});
initpimg();
initiate();
}
function initpimg(){
drawn = false;
pimg = createGraphics(w, h);
pimg.noStroke();
pimg.fill(255);
pimg.rect(0, 0, w, h);
pimg.noFill();
pimg.stroke(0);
pimg.strokeWeight(2);
var wr=.2;
var A=randomPoint(wr);
var B=randomPoint(wr);
var C =randomPoint(wr);
var D=randomPoint(wr);
var E=randomPoint(wr);
var F=randomPoint(wr);
pimg.bezier(A.x,A.y,B.x,B.y,C.x,C.y,D.x,D.y);pimg.bezier(D.x,D.y,2*D.x-C.x,2*D.y-C.y,E.x,E.y,F.x,F.y);
pimg.bezier(F.x,F.y,2*F.x-E.x,2*F.y-E.y,2*A.x-B.x,2*A.y-B.y,A.x,A.y);
pimg.loadPixels();
}
function initiate() {
cycles=[];
ncycles=acDef.ncycles;
flou = .7;
m = 1;
mt1=random(-3, 3);
mt2=random(-3, 3);
mt3=random(-3, 3);
m1 = random(1) > .5 ? random(.1, 3) : -random(.1, 3);
m2 = random(1) > .5 ? random(.1, 3) : -random(.1, 3);
m3 = random(1) > .5 ? random(.1, 3) : -random(.1, 3);
f0=random(-.0000005, .0000005);
f1=random(-3, 3);
f2=random(-3, 3);
f3=random(-3, 3);
t0 = random(.01);
epsilon = random(.0001, 0.01);
var bril=acDef.black_background?255:100;
for (var i=0; i<ncycles; i++) {
if (acDef.blackandwhite) {
cycles[i]=new Cycle(0, 0,bril+5*i, 8);
} else {
cycles[i]=new Cycle(acDef.hue+int(random(-acDef.max_hue_offset, acDef.max_hue_offset)), 255, bril+5*i, 8);
}
}
}
function randomPoint(a){
return createVector(.5*(1-a)*width+random(a*width),.5*(1-a)*height+random(a*height));
}
function draw() {
if (!drawing) {
for (var i=0; i<ncycles; i++) {//noprotect
cycles[i].update();
cycles[i].update();
}
}
}
function keyReleased() {
if (key == ' ') {
cycles=[];
initpimg();
initiate();
} else if (key == 's' || key == 'S') {
saveImage();
} else if (key == 'r' || key == 'R') {
initiate();
} else if (key == 'y' || key == 'Y') {
sym=!sym;
} else if (key == 'k' || key == 'K') {
blackandwhite=!blackandwhite;
for (var i=0; i<ncycles; i++) {
cycles[i].sat =blackandwhite?random(50,200): random(150,255);
}
}
}
function mouseDragged() {
if(mouseX<w-1.2*gui.width ||mouseY>1.2*gui.width){
if (!drawn) {
pimg.background(255);
drawn = true;
}
drawing=true;
var d = dist(mouseX, mouseY, pmouseX, pmouseY);
for (var i = 0; i < d; i++) {
pimg.point(pmouseX + int(i * (mouseX - pmouseX) / d), pmouseY + int(i * (mouseY - pmouseY) / d));
}
image(pimg, 0, 0);
}
}
function mouseWheel(event) {
flou += .001 * event.delta;
}
function mouseReleased() {
if(!fullscreen()){
fullscreen(true);
resizeCanvas(windowWidth,1.1*windowHeight);
}
if(drawn&&drawing){
loadPixels();
pimg.pixels=pixels.slice();
for (var i = 0; i < cycles.length; i++) {
cycles[i].initiate();
}
}
else if(mouseX<w-1.2*gui.width ||mouseY>1.2*gui.width)initiate();
drawing=false;
}
function saveImage(){
save("svimg" + day() + "_" + month() + "_" + hour() + "_" + minute() + "_" + second() + ".png");
}
function getImgPixelBrightness(x, y, img) {
var pos = 4 * (floor(x) + floor(y) * img.width);
bri = img.pixels[pos];
return bri;
}
(function () {
var loadJS = function(filename){
var script = document.createElement("script");
script.setAttribute("type","text/javascript");
script.setAttribute("src", filename);
document.getElementsByTagName("head")[0].appendChild(script);
}
loadJS("https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.5/dat.gui.min.js");
document.oncontextmenu = function() { return false; }
document.onmousedown = function() { return false; }
})();