Coding / Session 4

October 23, 2013 § Leave a comment

[Add and watch video on UniLearn when it’s added, noting down what certain code does]

In this session of coding we altered the code from the previous week again, this time making the brush strokes form the image itself, stroke by stroke, making for quite an abstract looking outcome. For this I decided to use a photo of myself, the results at the end show the process at the beginning and about 10 minutes in.

import processing.opengl.*;

PImage face;
int impos;

float curx;
float cury;
float targx;
float targy;
float brushsize;

void setup() {

  face=loadImage(“source.jpg”);
  size(face.width, face.height, OPENGL);

  curx=random(face.width);
  cury=random(face.height);
  targx=random(face.width);
  targy=random(face.height);
  brushsize=5+random(80);
}

void draw() {
  int arpos=int(cury)*face.width;
  // arpos = array position
  arpos=arpos+int(curx);
  color brushcol=face.pixels[arpos];
  // The above two lines of code colourises the pixels taken from the image
  // we want to set this colour
  fill(brushcol, 20);
  //this is changing the color of the brush to match the colours of the image
  stroke(brushcol, 20);
  ellipse(curx, cury, brushsize, brushsize);
  //fill(255,0,0);
  //rect(targx,targy,brushsize,brushsize);
  curx=curx+((targx-curx)/7);
  cury=cury+((targy-cury)/7);
  if (targx-curx<5) {
    //close on the x axis
    if (targy-cury<5) {
      //close on the y axis
      //give new values to the brush stroke
      curx=random(face.width);
      cury=random(face.height);
      targx=random(face.width);
      targy=random(face.height);
      brushsize=1+random(20);
    }
  }

  for (int lop=0;lop<80;lop=lop+1) {
    //the thing to do 80 times
    impos=int(random(face.width*face.height));
    color x=face.pixels[impos];
    stroke(red(x), green(x), blue(x), 40);
    fill(red(x), green(x), blue(x), 40);
    //rect(random(face.width),random(face.height),10,10);
    int drawy=impos/face.width;
    int drawx=impos-(drawy*face.width);
    //rect(drawx,drawy,10,10);
  }
}

screenshot

screenshot2

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Coding / Session 4 at Leo Patterson.

meta

%d bloggers like this: