Februar 27, 2012
Ein einfacher Video(Webcam) to ASCI converter: code:import processing.video.*; Capture myCapture; int pixel= 10; PFont myFont; void setup() { size(1280, 720); String s = "IIDC FireWire Video"; //println(Capture.list()); myCapture = new Capture(this, width, height,s,25); // Set the frameRate to read 4 new images per second myCapture.frameRate(25); myFont = createFont("FrutigerLTCom-Light-48.vlw", pixel); } void draw() { background(0); if (myCapture.available()) { myCapture.read(); } //image(myCapture, 0, 0); // println(Capture.list()); for (int y = 0; y { for (int x = 0; x < width; x+=pixel) { color c = getAvarageColor(myCapture, x, y, pixel, pixel); int bright = int(brightness(c)); int fontChar = int(map(bright, 0, 255, 0, 7)); int fontSize = int(map(bright, 0, 255, pixel, pixel*1.5)); //println(fontSize); noStroke(); fill(255); textFont(myFont,fontSize); switch(fontChar) { case 0: text(".", x, y); break; case 1: text("°", x, y); break; case 2: text("^", x, y); break; case 3: text("o", x, y); break; case 4: text("b", x, y); break; case 5: text("A", x, y); break; case 6: text("B", x, y); break; case 7: text("O", x, y); break; } } } } color getAvarageColor(Capture _img, int _posX, int _posY, int _w, int _h) { int vR = 0; int vG = 0; int vB = 0; for (int y=_posY; y { for (int x=_posX; x { vR += red(_img.get(x, y)); vG += green(_img.get(x, y)); vB += blue(_img.get(x, y)); } } return(color(vR/(_w*_h), vG/(_w*_h), vB/(_w*_h))); }