Browse Source

made modular

develop
Carmine De Rosa 6 years ago
parent
commit
c3aff0e659
  1. 23
      ephimera/ephimera.pde
  2. 68
      ephimera/percentage.pde

23
ephimera/ephimera.pde

@ -0,0 +1,23 @@
import processing.serial.*;
import processing.video.*;
Capture video;
int videoWidth = 640;
int videoHeight = 480;
void setup() {
size(640, 480);
frameRate(10);
colorMode(HSB, 100, 100, 100);
video = new Capture(this, width, height);
video.start();
background(0);
}
void draw() {
ephPercentage();
}

68
ephimera/percentage.pde

@ -0,0 +1,68 @@
int cellSize = 20;
int cols = videoWidth / cellSize;
int rows = videoHeight / cellSize;
int cellN = (cols)*(rows);
int[] colorValues = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
void ephPercentage() {
if (video.available()) {
video.read();
video.loadPixels();
for(int i = 0; i<colorValues.length; i++) {
colorValues[i] = 0;
}
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
int x = i*cellSize;
int y = j*cellSize;
int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image
// Get hue and brightness values
float hueVal = hue(video.pixels[loc]);
float briVal = brightness(video.pixels[loc]);
float satVal = saturation(video.pixels[loc]);
// Set pixel color
color c = color(hueVal, satVal, briVal);
// Check brightness values,
// if greater then 80% increace white counter,
// if lower then 20% increace black counter,
// otherwise increase color counters
if(briVal > 20 && briVal < 80) {
colorValues[int(hueVal/8.3)]++;
} else if(briVal <= 20) {
colorValues[12]++;
} else if(briVal >= 20) {
colorValues[13]++;
}
pushMatrix();
translate(x+cellSize/2, y+cellSize/2);
rectMode(CENTER);
fill(c);
noStroke();
rect(0, 0, cellSize+6, cellSize+6);
popMatrix();
}
}
// Print colors percentage values
for(int i = 0; i<colorValues.length-2; i++) {
//print(colorValues[i]/(float(cellN)/100) + "\t");
fill(color((i*8.3)+5, 100, 100));
rect(0, (i*5)+5, colorValues[i], 5);
}
fill(0);
rect(0, 65, colorValues[12], 5);
fill(100);
rect(0, 70, colorValues[13], 5);
println("");
}
}
Loading…
Cancel
Save