Image to Keyboard

edited December 2015 in Library Questions

I have a tiny question. If someone could help, I'd appreciate it a lot.

When I click play, I want the image to be at the stage when the mouse is at the right side of the screen. And as the user is typing, the image goes from high tot left (pixelated to clear image). How to connect the image to keyboard?

//variables for message function String message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam vel quam fermentum, blandit nulla vel, adipiscing sapien. Pellentesque nunc lectus, vestibulum a sollicitudin ac, vulputate vitae libero. Duis ut consectetur quam, ullamcorper faucibus est. Quisque quis dui ante. Vivamus ullamcorper, felis et feugiat faucibus, augue odio lacinia est, et tristique neque ligula eget mi. Morbi et nulla leo. Integer semper nibh erat, ac rutrum ante hendrerit id."; float textleft = 50, texttop = 50; float charw = 8, charh = 13; int lettersPerLine = 90; float xmargin = 400, ymargin = 750; int progress = 0; int[] asciivalues; //use this line to convert string to int[]

PImage img; int grid = 5;

import processing.video.*; Capture cam;

void setup() { size(displayWidth, displayHeight); textFont(createFont("Courier", 14), 14);

asciivalues = int( message.toCharArray() ); //use this line to convert string to int[]

cam = new Capture(this, width, height, 30); cam.start();

img = loadImage("01.png"); img = cam; background(0); smooth();

}

float getXPosition(int index) { return index%lettersPerLine * charw + xmargin; } float getYPosition(int index) { return int(index/lettersPerLine) * charh + ymargin;

}

void draw() {

// background(255);

timer(120);

picture(); pix(); message(); //rect(0, -180, width, height);

}

//message to be typed function void message() {

for (int i = 0; i < message.length (); i++) { fill(0); if (progress >= i) fill(100); if (progress == i) fill(255, 0, 0); textSize(14); text(message.charAt(i), getXPosition(i), getYPosition(i)); }

}

void keyPressed() { if (int(key) >= int(' ') && int(key) <= int('z')) { if (progress < message.length() && key == asciivalues[progress]) { progress++; int percentDone = floor(float(progress) / float(message.length())*100); println(percentDone); } } }

//timer function void timer(int interval) {

String time = "Time"; int t;

//background(255); t = interval - int(millis()/1000); time = nf(t, 2); if (t < 0) { time = ""; textSize(100); fill(255, 0, 0); noStroke(); text("STOP", width/2.5, height/1.12); message = ""; } text(time, width0.15, height0.9); }

//image function

void picture() { if (cam.available()) { cam.read(); } image(cam, 0, -180); //filter(GRAY); //filter(INVERT); //filter(THRESHOLD, 0.50); } void mousePressed() { image(cam, 0, 0); filter(GRAY); //filter(THRESHOLD, 0.50);

saveFrame("/Users/aminatayyub/Desktop/DC_Final/text_perc_cam_eurika_/data/01.png"); cam.stop();

}

//pixel to image function void pix() {

grid = mouseX+1; // Pick a random point

for (int x = 1; x < width; x+=grid) { for (int y = 0; y < height; y+=grid ) { int loc = x + y*img.width;

  // Look up the RGB color in the source image
  img.loadPixels();
  float r = red(img.pixels[loc]);
  float g = green(img.pixels[loc]);
  float b = blue(img.pixels[loc]);
  float gray = brightness(img.pixels[loc]);

  noStroke();

  // Draw an ellipse at that location with that color
  fill(r, g, b, 100);
  fill(gray);
  rect(x, y, grid, grid);
}

}

}

Answers

Sign In or Register to comment.