Advertisement
xeromino

image

Mar 12th, 2017
193
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PImage img;
  2. //float nz;
  3.  
  4. void setup() {
  5.   size(500, 540);
  6.   img = loadImage("photo2.jpg");
  7.   // surface.setResizable(true);
  8.   // surface.setSize(img.width, img.height);
  9.  
  10. }
  11.  
  12. void draw() {
  13.   // try uncommenting the following lines to get different effects   
  14.  
  15.   //image(img, 0, 0);
  16.   //distortImage();
  17.   //stampImage();
  18.   //colorCircles();
  19.   //dripColorManu();
  20.   //dripColorAuto();
  21.   //feedbackloop();
  22.   //feedbackloop2();
  23.   //colorLines();
  24.   //filterStuff();
  25.   //filterStuff2();
  26. }
  27.  
  28. void distortImage() {
  29.   //background(0);
  30.   // make image semi-transparent with tint(255,x);
  31.   tint(255, 50);
  32.   // use mouse positions as the width and height of the image
  33.   image(img, 0, 0, mouseX, mouseY);
  34. }
  35.  
  36. void stampImage() {
  37.   img.resize(width/2, height/2);
  38.   // make the center of the image the starting point
  39.   //imageMode(CENTER);
  40.   //tint(255, 50);
  41.   // only do a certain thing if the mouse is pressed
  42.   //if (mousePressed) {
  43.   image(img, mouseX, mouseY);
  44.   //}
  45. }
  46.  
  47. void colorCircles() {
  48.   // choose a random size for the circle
  49.   float sz = random(5, 25);
  50.   // get the color of the pixel where the mouse is
  51.   color c = img.get(mouseX, mouseY);
  52.   fill(c);
  53.   stroke(255, 150);
  54.   if (mousePressed) {
  55.     ellipse(mouseX, mouseY, sz, sz);
  56.   }
  57. }
  58.  
  59. void dripColorManu() {
  60.   color c = img.get(mouseX, mouseY );
  61.   fill(c, random(100, 150));
  62.   noStroke();
  63.   if (mousePressed) {
  64.     // paint 'drips' of varying sizes
  65.     rect(mouseX, mouseY, random(1, 5), random(5, 100), 3);
  66.   }
  67. }
  68.  
  69. void dripColorAuto() {
  70.   int x = (int) random(width);
  71.   int y =  (int) random(height);
  72.   color c = img.get(x, y );
  73.   fill(c, random(100, 150));
  74.   noStroke();
  75.   rect(x, y, random(1, 10), random(5, 100), 3);
  76. }
  77.  
  78. void feedbackloop() {
  79.   // [slices]
  80.   // slow the sketch down to better see what's going on
  81.   frameRate(15);
  82.   // determine the location to cut from
  83.   int x1 = 0;
  84.   int y1 = (int) random(height);
  85.   // determine the offset for the paste
  86.   int y2 = int(y1 + random(-7, 7));
  87.   int x2 = int(random(-5, 5));
  88.   // the height of the slice should vary
  89.   int w = width;
  90.   int h = (int) random(5, 10);
  91.   // copy the slice to its new location
  92.   copy(x1, y1, w, h, x2, y2, w, h);
  93. }
  94.  
  95. void feedbackloop2() {
  96.   // [squares]
  97.   frameRate(15);
  98.   // determine a random location to cut from
  99.   int x1 = (int) random(width);
  100.   int y1 = (int) random(height);
  101.   // determine the offset for the paste
  102.   int x2 = int(x1 + random(-10, 10));
  103.   int y2 = int(y1 + random(-10, 10));
  104.   // we're copying squares here
  105.   int w = 100;
  106.   int h = 100;
  107.   // copy the square to the new place
  108.   copy(x1, y1, w, h, x2, y2, w, h);
  109. }
  110.  
  111. void colorLines() {
  112.   // create horizontal lines starting in the middle of the image, using the color of the corresponding pixel
  113.   image(img, 0, 0);
  114.   // do the following for each horizontal line (of the image)
  115.   for (int y = 0; y <height; y++) {
  116.     // position x at the middle of the width
  117.     int x = width/2;
  118.     // get the color of that pixel
  119.     color col = get(x, y);
  120.     // map the length of that line to the horizontal position of the mouse
  121.     float lineLength = map(mouseX, 0, width, -300, 300);
  122.     // map the transparency of that line to the vertical position of the mouse
  123.     float alpha = map(mouseY, 0, height, 100, 255);
  124.     // apply that transparency to that line
  125.     stroke(col, alpha);
  126.     // draw that line
  127.     line(x, y, x+lineLength, y);
  128.     // add a twist to it
  129.     //float offSetY = map(y, 0, height, lineLength, -lineLenght);
  130.     //line(x, y, x+offSetY, y);
  131.   }
  132. }
  133.  
  134. void filterStuff() {
  135.   image(img, 0, 0);
  136.   // change color mode from Red Green Blue to Hue Saturation Brightness
  137.   colorMode(HSB);
  138.   // load the pixels of the image
  139.   loadPixels();
  140.   // loop through all the pixels
  141.   for (int i=0; i<pixels.length; i++) {
  142.     // get the hue, saturation and brightness of each pixel
  143.     float h = hue(pixels[i]);
  144.     float s = saturation(pixels[i]);
  145.     float b = brightness(pixels[i]);
  146.     // modify the color information of the pixel
  147.     //if (i>pixels.length/2)
  148.     pixels[i] = color(h, 255-s, b);
  149.   }
  150.   // update the pixels to see the result
  151.   updatePixels();
  152. }
  153.  
  154. void filterStuff2() {
  155.   // noise example just to show what's possible
  156.   image(img, 0, 0);
  157.   colorMode(HSB);
  158.   loadPixels();
  159.   float nx = 0;
  160.   float ny = 0;
  161.   for (int x=0; x<width; x++) {
  162.     ny = 0;
  163.     for (int y=0; y<height; y++) {
  164.       float ns = noise(nx, ny, nz);
  165.       float h = hue(img.get(x, y));
  166.       float s = saturation(img.get(x, y));
  167.       float b = brightness(img.get(x, y));
  168.       if (ns > 0.5) pixels[y*width+x] = color(h, 255-s, b);
  169.       ny += 0.005;
  170.     }
  171.     nx += 0.005;
  172.   }
  173.   updatePixels();
  174.   nz += 0.007;
  175. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement