Source Code. Projects. Nerd Stuff. Art Stuff.

Images and Camera

 

[gn_spoiler title="spotlightBlackout" open="0" style="1"]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
PImage img;
PImage displayImg;

void setup() {
  frameRate(10);
  size(640, 480);
  img = loadImage("http://theflavorful.com/wp-content/uploads/2012/10/niagara.jpeg");
  displayImg = new PImage(640, 480);
}

void draw() {

  noStroke();

  for (int x = 0; x < img.width; x++) {
    for (int y = 0; y < img.height; y++) {
      // Formula for manipulating pixel array
      int index = x + y * img.width;
      displayImg.pixels[index] = img.pixels[index];

      color c = img.pixels[index];

      if (dist(x, y, mouseX, mouseY) < 100) {
        displayImg.pixels[index] = img.pixels[index];
      }
      else {
        displayImg.pixels[index] = color(0);
      }
    }
  }

  displayImg.updatePixels();

  image(displayImg, 0, 0);
}
[/gn_spoiler]

 

[gn_spoiler title="pixelColorManip" open="0" style="1"]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
PImage img;

void setup() {
  frameRate(10);
  size(640, 480);
  img = loadImage("http://theflavorful.com/wp-content/uploads/2012/10/niagara.jpeg");
}

void draw() {
 
//  noStroke();

  for (int x = 0; x < img.width; x+=10) {
    for (int y = 0; y < img.height; y+=10) {
      // Formula for manipulating pixel array
      int index = x + y * img.width;
      // Get pixel colors
      color c = img.pixels[index];
      c += hue(100);
      fill(c);
      // Make circles out of pixels
      ellipse(x, y, 10, 10);
    }
  }
}
[/gn_spoiler]

 

[gn_spoiler title="ellipseVideo" open="0" style="1"]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import processing.video.*;

Capture cam;
PImage displayImg;

void setup() {
  size(640, 480);

  cam = new Capture(this, 640, 480);
  cam.start();

  displayImg = new PImage(640, 480);
}

void captureEvent() {
}

void draw() {
  if (cam.available()) {
    cam.read();

    for (int x = 0; x < cam.width; x+=10) {
      for (int y = 0; y < cam.height; y+=10) {
        // (width - x - 1) refers to a reversed image
        int dIndex = x + y * cam.width;  // display index
        int cIndex = (width - x - 1) + y * cam.width;  // camera index

        // getting pixels for displayImg from cam.pixels
        // putting pixels back into index in reverse order
//        displayImg.pixels[dIndex] = cam.pixels[cIndex];
        fill(cam.pixels[cIndex]);
        ellipse(x + random(-2, 2), y + random(-2, 2), 10, 10);
      }
    }

    //  displayImg.updatePixels();

    //  image(displayImg, 0, 0);
  }
}
[/gn_spoiler]