// smoothTracer // by Pablo Tamarit // built with processing-0056 boolean mouseDown = false; boolean mouseDownFirst = true; boolean modeRandom = true; float randMax = 100; int nbPoints = 200; float[][] points = new float[nbPoints][2]; // [][0]==x; [][1]==y; int colorInit = 254; float colorPas; int posX = 0; int posY = 0; int longX = 401; int longY = 401; void setup() { size(401,401); background(255); for (int i=0; i < nbPoints; i++) { points[i][0] = (longX/2)+posX; points[i][1] = (longY/2)+posY; } colorPas = float(254.0/(nbPoints-2)); println(colorPas); mouseX = (longX/2)+posX; mouseY = (longY/2)+posY; } void loop() { drawLineStrip(); moveLineStrip(); drawCadre(); } void drawLineStrip() { float colorAct = colorInit; for (int i=nbPoints-1; i > 0; i--) { stroke(colorAct); line(points[i][0], points[i][1], points[i-1][0], points[i-1][1]); colorAct -= colorPas; colorAct = constrain(colorAct,0,254); } } void moveLineStrip() { if (mouseIsClicked()) { modeRandom = !modeRandom; } if (modeRandom) { float randValX = random(randMax); float randValY = random(randMax); randValX = randMax/2 - randValX; randValY = randMax/2 - randValY; points[0][0] = constrain(randValX+points[0][0], posX, posX+longX); points[0][1] = constrain(randValY+points[0][1], posY, posY+longY); } else { points[0][0] = constrain(mouseX, posX, posX+longX); points[0][1] = constrain(mouseY, posY, posY+longY); } for (int i=nbPoints-1; i > 0; i--) { points[i][0] = (points[i][0] + points[i-1][0]) / 2; points[i][0] = constrain(points[i][0], posX, posX+longX); points[i][1] = (points[i][1] + points[i-1][1]) / 2; points[i][1] = constrain(points[i][1], posY, posY+longY); } } void drawCadre() { noFill(); stroke(0); rect(posX,posY,longX-1,longY-1); } boolean mouseIsClicked() { boolean _mouseIsClicked = false; if (mouseDown && mouseDownFirst) { _mouseIsClicked = true; mouseDownFirst = false; } else if (!mouseDown) { mouseDownFirst = true; } return _mouseIsClicked; } void mousePressed() { mouseDown = true; } void mouseReleased() { mouseDown = false; }