Advertisement
Guest User

Untitled

a guest
Nov 19th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. String [] poem1 ={"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
  2. String [] poem ={"e", "x", "m", "a", "c", "h", "i", "n", "a", "c", "t", "r", "l", "o", "r", "g", "m", "o", "d", "e", "i", "c", "e", "n", "o", "x"};
  3.  
  4. String loadPath = "./sample.jpg"
  5. PImage picture;
  6. int devisions = 1; // pixels
  7. PFont font;
  8. float xDiv;
  9. float yDiv;
  10.  
  11. void setup() {
  12.   picture = loadImage(loadPath);
  13.   size(780, 439);
  14.   font = createFont("Kokoner", 1);
  15.   xDiv = picture.width/devisions;
  16.   yDiv = picture.height/devisions;
  17. }
  18.  
  19. void draw() {
  20.   background(255);
  21.   textFont(font, devisions+3);
  22.   for (int i = 0; i < height; i+= devisions) {
  23.     for (int j = 0; j < width; j+= devisions) {
  24.       color filler = picture.get(int(j), int(i));
  25.       fill(color(red(filler), green(filler), blue(filler)));
  26.       //gets char depending on brightness
  27.       float value = brightness(filler);
  28.       String charac = poem[int(random(poem.length))];
  29.       text(charac, (j), (i));
  30.     }
  31.   }
  32. }
  33.  
  34. void keyPressed() {
  35.   if (key == CODED) {
  36.     if (keyCode == UP) {
  37.       devisions++;
  38.     } else if (keyCode == DOWN) {
  39.       if (devisions > 0) {
  40.         devisions--;
  41.       };
  42.     }
  43.   }
  44.   if (key == 'e') {
  45.     draw();
  46.   }
  47.   constrain(devisions, 1, 99);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement