Scratch painting technique!?

An example image of the cat that manipulate with this code.

Image manipulation result with the image from 'Orange And White Cat Closeup'
http://www.photos-public-domain.com/2011/01/07/orange-and-white-cat-closeup/

 

An example image of the two cats that manipulate with this code.

Image manipulation result with the image from 'Two Tabby Cats'
http://www.photos-public-domain.com/2016/11/15/two-tabby-cats/

 

Description of this creative coding.

It's a creative coding work of image manipulation made with the 'Processing'.

I wanted to make etching looks, so I tried to draw an image with lines with four directions. It was looking good but I felt something was different from what I imagined first. And I've forgotten what I imagined first already. XP

 

You can use your photo with this code.

You can do hard coding the path of your photo image file or you can give command line parameter like this.

/your_processing_installed_path/processing-java --force --sketch=/your_sketch_path/ --run /your_photo_file_path

This code does not display any images on the screen but generates image files in frames directory.





 

The 'Processing' code example.

Please feel free to use this example code under the terms of the GPL. To see other works based on my code is my pleasure. And my honor.


// Cat Scratch Fever.
// @author @deconbatch
// @version 0.2
// Processing 3.2.1
// 0.1 2018.02.07
// 0.2 2018.12.23

/* ---------------------------------------------------------------------- */
abstract class PshapeElement {

  PShape anElement;
  float elementColor, elementSaturation, elementBright, elementAlpha;
  
  PshapeElement() {
    anElement = pscreateElement();
    elementColor = 0;
    elementSaturation = 0;
    elementBright = 0;
    elementAlpha = 0;
  }

  abstract PShape pscreateElement();

  void setElementFill(float pcolor, float psaturation, float pbright, float palpha) {
    elementColor = pcolor;
    elementSaturation = psaturation;
    elementBright = pbright;
    elementAlpha = palpha;
    resetColor();
  }

  void resetColor() {
    anElement.setStroke(color(elementColor, elementSaturation, elementBright, elementAlpha));
  }

  void changeColor(float scolor) {
    elementColor = scolor;
    resetColor();
  }

  void changeBright(float sbright) {
    elementBright = sbright;
    resetColor();
  }

  void resetSize() {
    anElement.resetMatrix();
  }

  void changeSize(float scaleX, float scaleY) {
    anElement.scale(scaleX, scaleY);
  }

  void rotate(float radX) {
    anElement.rotate(radX);
  }

  void show() {
    shape(anElement);
  }

}

/* ---------------------------------------------------------------------- */
class LineBrush extends PshapeElement {

  
  LineBrush() {
    super();
  }

  PShape pscreateElement() {

    noFill();
    PShape psDp = createShape(LINE, -2.0, 0.0, 2.0, 0.0);
    return psDp;

  }

}

/* ---------------------------------------------------------------------- */

float baseWH;

void setup() {

  size(1080, 1080);
  baseWH = 980;
  
  colorMode(HSB, 360, 100, 100, 100);
  strokeWeight(0.03); // sensitive
  smooth(8);
  noLoop();

}

void draw() {

  float maxBrightness = 30.0;
  float maxSaturation = 20.0;

  PImage img;
  PshapeElement brush = new LineBrush();
    
  if (args == null) {
    // you can use your photo in ./data/your_image.jpg
    img = loadImage("your_image.jpg");
  } else {
    // args[0] must be image path
    img = loadImage(args[0]);
  }

  // fit to canvas size
  float rateSize = baseWH / max(img.width, img.height);
  float canvasW  = img.width * rateSize;
  float canvasH  = img.height * rateSize;

  img.resize(int(canvasW), int(canvasH));
  img.loadPixels();

  background(0.0, 0.0, 90.0, 0.0);
  translate((width - canvasW) / 2, (height - canvasH) / 2);

  // Draw background
  for (int idxW = 0; idxW < img.width; ++idxW) {  
    for (int idxH = 0; idxH < img.height; ++idxH) {

      int idxPoint = idxH * img.width + idxW;
      color cPoint = img.pixels[idxPoint];

      float valSiz    = random(2.0, 10.0);
      float valRotate = map(random(1.0), 0.0, 1.0, -90.0, 90.0);
      float valHue    = hue(cPoint);
      float valSat    = map(saturation(cPoint), 0.0, 100.0, 0.0, maxSaturation);
      float valBri    = map(brightness(cPoint), 0.0, 100.0, 0.0, maxBrightness);
      float valAlp    = 100.0;
        
      pushMatrix();
      translate(idxW, idxH);
      brush.resetSize();
      brush.changeSize(valSiz, valSiz);
      brush.rotate(radians(valRotate));
      brush.setElementFill(valHue, valSat, valBri, valAlp);
      brush.show();
      popMatrix();

    }
  }

  // Draw scratch
  blendMode(SCREEN);
  float noiseW      = random(100.0);
  float noiseHStart = random(100.0);
  int   idxMult     = 4;
  
  for (int idxW = 0; idxW < img.width; idxW += idxMult) {  
    float noiseH = noiseHStart;
    for (int idxH = 0; idxH < img.height; idxH += idxMult) {

      int idxPoint = idxH * img.width + idxW;
      color cPoint = img.pixels[idxPoint];

      float valSiz = map(noise(noiseH, noiseW), 0.0, 1.0, 1.0, 3.0);
      valSiz += abs(map(saturation(cPoint), 0.0, 100.0, -8.0, 3.0));
      valSiz += abs(map(brightness(cPoint), 0.0, 100.0, -3.0, 8.0));

      float valRotate = map(noise(noiseW, noiseH), 0.0, 1.0, -90.0, 90.0);
      valRotate += map(hue(cPoint), 0.0, 360.0, -360.0, 360.0);
      valRotate += map(brightness(cPoint), 0.0, 100.0, -360.0, 360.0);
      if (abs(valRotate) < 45.0 && saturation(cPoint) < 5.0) {
        valRotate += map(noise(noiseH * 2.0, noiseW * 2.0), 0.0, 1.0, -90.0, 90.0);
      }
      valRotate = int(ceil((valRotate % 360) / 45.0)) * 45.0;

      float valHue = (hue(cPoint) + map(noise(noiseW, noiseH), 0.0, 1.0, -30.0, 30.0) + 360) % 360;
      float valSat = map(saturation(cPoint), 0.0, 100.0, 0.0, maxSaturation);
      float valBri = map(brightness(cPoint), 0.0, 100.0, 0.0, maxBrightness);

      float scratchRate = noise(noiseW, noiseH) + noise(noiseH, noiseW);
      if (scratchRate < 0.5) {
        valHue = 0.0;
        valSat = 90.0;
        valBri = 16.0 * scratchRate;
        valSiz *= 6.0 * scratchRate;
    } else {      
      if ((idxW + idxH) % (8 * idxMult) == 0) {
        // nop
      } else if ((idxW + idxH) % (4 * idxMult) == 0) {
        valSat += maxSaturation * 1.5;
        valBri += maxBrightness;
      } else if ((idxW + idxH) % (2 * idxMult) == 0) {
        valSat += maxSaturation;
        valBri += maxBrightness * 1.5;
      }
    }
      float valAlp = 100;
        
      pushMatrix();
      translate(idxW, idxH);
      brush.resetSize();
      brush.changeSize(valSiz, valSiz);
      brush.rotate(radians(valRotate));
      brush.setElementFill(valHue, valSat, valBri, valAlp);
      brush.show();
      popMatrix();

      noiseH += 0.02;

    }
    
    noiseW += 0.02;

  }

  saveFrame("frames/0001.png");
  exit();
  
}

/*
Copyright (C) 2018- deconbatch

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>
*/



 

Next Post Previous Post
No Comment
Add Comment
comment url