HairiCat

A brush painting like cat photo that was made with Processing programming language.

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


A brush painting like cat photo that was made with Processing programming language.

Example result with the image from
Calico Kitten In Sunbeam
http://www.photos-public-domain.com/2010/08/28/calico-kitten-in-sunbeam/


Description of this image manipulation code.

Image manipulation type creative coding made with Processing.
This is a revised version of AmplifiCat.

It makes a photo of brush painting art.

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

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


Processing code examples.

Please feel free to use it, if you like it.
To see other works based on my code is my pleasure. And my honor.

// HairiCat.
// @author @deconbatch
// @version 0.2
// Processing 3.2.1
// 0.1 2017.06.11
// 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 BoxBrush extends PshapeElement {

  
  BoxBrush() {
    super();
  }

  PShape pscreateElement() {

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

  }

}

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

PImage img;
PshapeElement brush;

float canvasW, canvasH;
float rateSize;

void setup() {
  size(1080, 1080);
  float baseWH = 980;
  
  colorMode(HSB, 360, 100, 100, 100);
  strokeWeight(0.01);
  smooth(8);
  noLoop();

  brush = new BoxBrush();

  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
  rateSize = baseWH / max(img.width, img.height);
  canvasW = img.width * rateSize;
  canvasH = img.height * rateSize;
  img.resize(int(canvasW), int(canvasH));
  img.loadPixels();

}

void draw() {

  float maxBrightness = 90;
  
  background(0, 0, maxBrightness);
  translate((width - canvasW) / 2, (height - canvasH) / 2);

  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 valSize = 1.0;
      valSize += map(saturation(cPoint), 0.0, 100.0, 0.0, 10.0);
      valSize += abs(map(brightness(cPoint), 0.0, 100.0, -15.0, 2.0));

      float valRotate = 0;
      valRotate += map(brightness(cPoint), 0.0, 100.0, 0.0, 360.0);
      valRotate += map(saturation(cPoint), 0.0, 100.0, -30.0, 30.0);

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

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

}


/*
Copyright (C) 2017- 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 
*/





No comments :

Post a Comment