Guest User

Untitled

a guest
Jul 22nd, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. final int len=25;
  2. final float thresh=170;
  3.  
  4. boolean newDesign=false;
  5. PImage pic;
  6.  
  7. ArrayList<PImage> imgContainer;
  8. int n=3;
  9.  
  10. void setup() {  
  11.   size(800, 800, P2D);
  12.   colorMode(RGB, 255);
  13.   background(250, 250, 250);
  14.   rectMode(CENTER);
  15.   //imageMode(CENTER);
  16.  
  17.   pic=loadImage("hand.jpg");
  18.   pic.resize(width, height);
  19.   pic.filter(THRESHOLD, 0.8);
  20.   color c1 = color(200,25,25);
  21.   color c2 = color(25, 255, 200);  
  22.  
  23.   imgContainer=new ArrayList<PImage>();
  24. PImage pimg1=loadImage("test1.png");
  25. pimg1.resize(25, 25);
  26. imgContainer.add(pimg1);
  27. PImage pimg2=loadImage("test2.png");
  28. pimg2.resize(25, 25);
  29. imgContainer.add(pimg2);
  30. PImage pimg3=loadImage("test3.png");
  31. pimg1.resize(25, 25);
  32. imgContainer.add(pimg3);
  33.   noLoop();
  34.   noStroke();
  35. }
  36.  
  37. void draw() {
  38.   if (newDesign==false) {
  39.     return;
  40.   }
  41.  
  42.   pic.loadPixels();
  43.  
  44.   for (int y = 0; y < height; y+=18) {
  45.     for (int x = 0; x < width; x+=18) {
  46.       // Get the color stored in the pixel
  47.       int index=y*width+x;
  48.       color pixelValue = pic.pixels[index];
  49.       // Determine the brightness of the pixel
  50.       float pixelBrightness = brightness(pixelValue);
  51.  
  52.       float imgPicked=constrain(pixelBrightness/thresh, 0, n-1);
  53.       image(imgContainer.get((int)imgPicked),x,y);
  54.  
  55.     }
  56.   }
  57. }
  58. void mouseReleased() {
  59.   newDesign=!newDesign;
  60.   redraw();
  61. }
Advertisement
Add Comment
Please, Sign In to add comment