Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. import controlP5.*;
  2.  
  3. PImage img;
  4.  
  5. //brightness hue and saturation
  6. int brightness1 = 100;
  7. int hue1 = 100;
  8. int sat1 = 100;
  9.  
  10.  
  11. //filter
  12. int filter1 = 900;
  13. int cellsize = 2;
  14. int cols, rows;
  15.  
  16. //inverted
  17. boolean Toggleinvert = false;
  18. boolean ToggleFilter = false;
  19. int new_color;
  20.  
  21. //
  22.  
  23. ControlP5 debugUI;
  24.  
  25. void setup()
  26. {
  27.  
  28. size (900,900,P3D);
  29. colorMode(HSB,255);
  30.  
  31. cols = width/cellsize;
  32. rows = height/cellsize;
  33.  
  34. img = loadImage("skyOctopus.jpg");
  35.  
  36. debugUI = new ControlP5(this);
  37.  
  38. debugUI.addSlider("brightness1")
  39. .setPosition (0, height -25)
  40. .setSize (100,20)
  41. .setRange(0,100);
  42.  
  43. debugUI.addSlider("hue1")
  44. .setPosition (0, height -50)
  45. .setSize (100,20)
  46. .setRange(0,100);
  47.  
  48. debugUI.addSlider("sat1")
  49. .setPosition (0, height -75)
  50. .setSize (100,20)
  51. .setRange(0,100);
  52.  
  53.  
  54. debugUI.addToggle("Toggleinvert")
  55. .setPosition(0,height - 120)
  56. .setSize(50,20);
  57.  
  58.  
  59. debugUI.addToggle("ToggleFilter")
  60. .setPosition (00, height -160)
  61. .setSize (50,20);
  62.  
  63. debugUI.addSlider("filter1")
  64. .setPosition (0, height - 190)
  65. .setSize (100,20)
  66. .setRange(0,900);
  67.  
  68.  
  69.  
  70. }
  71.  
  72. void draw()
  73. {
  74.  
  75. background(0);
  76.  
  77. PImage imgCopy = img.get();
  78. imgCopy.loadPixels();
  79.  
  80. //BRIGHTNESS
  81. float brightRatio = (float)brightness1/100.0f;
  82. float HueRatio = (float)hue1/100.0f;
  83. float SatRatio = (float)sat1/100.0f;
  84.  
  85.  
  86. for (int i =0; i < imgCopy.pixels.length; i++)
  87. {
  88.  
  89. color prevCol = imgCopy.pixels[i];
  90. color newCol = color(hue(prevCol)* HueRatio, saturation(prevCol) * SatRatio, brightness(prevCol)*brightRatio);
  91.  
  92. if (Toggleinvert)
  93. {
  94. colorMode(RGB,255,255,255);
  95. new_color = color(255-red(new_color), 255-green(new_color), 255-blue(new_color));
  96. }
  97.  
  98. imgCopy.pixels[i] = newCol;
  99.  
  100. }
  101.  
  102.  
  103. imgCopy.updatePixels(); //updates the pixel
  104.  
  105. if (ToggleFilter) {
  106.  
  107. filter();
  108.  
  109. }
  110. else {
  111. image(imgCopy, 0, 0, width, height); //draws the pixels
  112. }
  113.  
  114.  
  115. }
  116.  
  117.  
  118. void filter() {
  119.  
  120. img.loadPixels();
  121. float filterRatio = (float)filter1;
  122. for ( int c = 0; c < cols; c++) {
  123. // Begin loop for rows
  124. for ( int r = 0; r < rows; r++) {
  125. colorMode(HSB,255,255,255);
  126. int x = c*cellsize + cellsize/2; // x position
  127. int y = r*cellsize + cellsize/2; // y position
  128. int loc = x + y*width; // Pixel array location
  129. color b = img.pixels[loc]; // Grab the color
  130. // Calculate a z position as a function of mouseX and pixel brightness
  131. float z = (filterRatio/(float)width) * brightness(img.pixels[loc]) - 100.0;
  132. // Translate to the location, set fill and stroke, and draw the rect
  133. pushMatrix();
  134. translate(x,y,z);
  135. fill(b);
  136. noStroke();
  137. rectMode(CENTER);
  138. rect(0,0,cellsize,cellsize);
  139. popMatrix();
  140. }
  141. }
  142.  
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement