Processing Day 14: Load Images

I’ve been experimenting with loading images into Processing recently and was able to load images on the keystroke.

For the following example, click on the window with your mouse to load the code and then type on your keyboard. My experimental gestural letterforms I created last semester will load with their corresponding keys.

I was also able to correspond the keystroke and load images with sounds. However I was not able to upload it to openprocessing.org because it utilizes the minim library, and openprocessing.org as of right now does not support the use of libraries.

Here is the code:

// Click on the window to give it focus,
// and press the 'B' key.

PImage A;
PImage B;
PImage C;
PImage D;
PImage E;
PImage F;
PImage G;
PImage H;
PImage I;
PImage J;
PImage K;
PImage L;
PImage M;
PImage N;
PImage O;
PImage P;
PImage Q;
PImage R;
PImage S;
PImage T;
PImage U;
PImage V;
PImage W;
PImage X;
PImage Y;
PImage Z;


void setup() {
  size(700, 500);
  background(#00A296);

  A = loadImage("A-web.png"); 
  B = loadImage("B-web.png"); 
  C = loadImage("C-web.png"); 
  D = loadImage("D-web.png"); 
  E = loadImage("E-web.png"); 
  F = loadImage("F-web.png"); 
  G = loadImage("G-web.png"); 
  H = loadImage("H-web.png"); 
  I = loadImage("I-web.png"); 
  J = loadImage("J-web.png"); 
  K = loadImage("K-web.png"); 
  L = loadImage("L-web.png"); 
  M = loadImage("M-web.png"); 
  N = loadImage("N-web.png"); 
  O = loadImage("O-web.png"); 
  P = loadImage("P-web.png"); 
  Q = loadImage("Q-web.png"); 
  R = loadImage("R-web.png"); 
  S = loadImage("S-web.png"); 
  T = loadImage("T-web.png"); 
  U = loadImage("U-web.png"); 
  V = loadImage("V-web.png"); 
  W = loadImage("W-web.png"); 
  X = loadImage("X-web.png"); 
  Y = loadImage("Y-web.png"); 
  Z = loadImage("Z-web.png"); 
}

void draw() {
  if (keyPressed) {
    if (key == 'A' || key == 'a') {
  image(A, 0, 0);
}  

  if (key == 'B' || key == 'b') {
  image(B, 150, 0);
}

if (key == 'C' || key == 'c') {
  image(C, 300, 0);
}  

  if (key == 'D' || key == 'd') {
  image(D, 450, 0);
}

if (key == 'E' || key == 'e') {
  image(E, 600, 0);
}  

  if (key == 'F' || key == 'f') {
  image(F, 750, 0);
}

if (key == 'G' || key == 'g') {
  image(G, 900, 0);
}  

  if (key == 'H' || key == 'h') {
  image(H, 1050, 0);
}

  if (key == 'I' || key == 'i') {
  image(I, 1200, 0);
}

if (key == 'J' || key == 'j') {
  image(J, 0, 200);
}  

  if (key == 'K' || key == 'k') {
  image(K, 150, 200);
}

if (key == 'L' || key == 'l') {
  image(L, 300, 200);
}

if (key == 'M' || key == 'm') {
  image(M, 450, 200);
}  

  if (key == 'N' || key == 'n') {
  image(N, 600, 200);
}

if (key == 'O' || key == 'o') {
  image(O, 750, 200);
}

if (key == 'P' || key == 'p') {
  image(P, 900, 200);
}

if (key == 'Q' || key == 'q') {
  image(Q, 1050, 200);
}  

  if (key == 'R' || key == 'r') {
  image(R, 1200, 200);
}

if (key == 'S' || key == 's') {
  image(S, 0, 400);
}

if (key == 'T' || key == 't') {
  image(T, 150, 400);
}

if (key == 'U' || key == 'u') {
  image(U, 300, 400);
}  

  if (key == 'V' || key == 'v') {
  image(V, 450, 400);
}

if (key == 'W' || key == 'w') {
  image(W, 600, 400);
}

if (key == 'X' || key == 'x') {
  image(X, 750, 400);
}

if (key == 'Y' || key == 'y') {
  image(Y, 900, 400);
}  

  if (key == 'Z' || key == 'z') {
  image(Z, 1050, 400);
}

} else {
    background(#00A296);
  }
   }