Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 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.   color c1 = color(200,25,25);
  20.   color c2 = color(25, 255, 200);  
  21.  
  22.   imgContainer=new ArrayList<PImage>();
  23. PImage pimg1=loadImage("test1.png");
  24. pimg1.resize(50, 50);
  25. imgContainer.add(pimg1);
  26. PImage pimg2=loadImage("test2.png");
  27. pimg2.resize(50, 50);
  28. imgContainer.add(pimg2);
  29. PImage pimg3=loadImage("test3.png");
  30. pimg1.resize(50, 50);
  31. imgContainer.add(pimg3);
  32.   noLoop();
  33.   noStroke();
  34. }
  35.  
  36. void draw() {
  37.   if (newDesign==false) {
  38.     return;
  39.   }
  40.  
  41.   pic.loadPixels();
  42.  
  43.   for (int y = 0; y < height; y+=40) {
  44.     for (int x = 0; x < width; x+=40) {
  45.       int index=y*width+x;
  46.       color pixelValue = pic.pixels[index];
  47.       color rgb = pixelValue;
  48.       int r = (rgb >> 16) & 0xFF;  // Faster way of getting red(argb)
  49.       int g = (rgb >> 8) & 0xFF;   // Faster way of getting green(argb)
  50.       int b = rgb & 0xFF;  
  51.  
  52. //How far is the current color from white
  53. float dista=dist(r,g,b,255,255,255);
  54.  
  55. //50 is a threshold value allowing close to white being identified as white
  56. //This value needs to be adjusted based on your actual background color
  57. //Next block is processed only if the pixel not white
  58. if(dista>30){    
  59.       float pixelBrightness = brightness(pixelValue);
  60.       float imgPicked=constrain(pixelBrightness/thresh, 0, n-1);
  61.       image(imgContainer.get((int)imgPicked),x,y);
  62. }
  63.     }
  64.   }
  65. }
  66.      
  67.      
  68.      
  69. void mouseReleased() {
  70.   newDesign=!newDesign;
  71.   redraw();
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement