Advertisement
daddydean2

Untitled

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