Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import controlP5.*;
- PImage img;
- //brightness hue and saturation
- int brightness1 = 100;
- int hue1 = 100;
- int sat1 = 100;
- //filter
- int filter1 = 900;
- int cellsize = 2;
- int cols, rows;
- //inverted
- boolean Toggleinvert = false;
- boolean ToggleFilter = false;
- int new_color;
- //
- ControlP5 debugUI;
- void setup()
- {
- size (900,900,P3D);
- colorMode(HSB,255);
- cols = width/cellsize;
- rows = height/cellsize;
- img = loadImage("skyOctopus.jpg");
- debugUI = new ControlP5(this);
- debugUI.addSlider("brightness1")
- .setPosition (0, height -25)
- .setSize (100,20)
- .setRange(0,100);
- debugUI.addSlider("hue1")
- .setPosition (0, height -50)
- .setSize (100,20)
- .setRange(0,100);
- debugUI.addSlider("sat1")
- .setPosition (0, height -75)
- .setSize (100,20)
- .setRange(0,100);
- debugUI.addToggle("Toggleinvert")
- .setPosition(0,height - 120)
- .setSize(50,20);
- debugUI.addToggle("ToggleFilter")
- .setPosition (00, height -160)
- .setSize (50,20);
- debugUI.addSlider("filter1")
- .setPosition (0, height - 190)
- .setSize (100,20)
- .setRange(0,900);
- }
- void draw()
- {
- background(0);
- PImage imgCopy = img.get();
- imgCopy.loadPixels();
- //BRIGHTNESS
- float brightRatio = (float)brightness1/100.0f;
- float HueRatio = (float)hue1/100.0f;
- float SatRatio = (float)sat1/100.0f;
- for (int i =0; i < imgCopy.pixels.length; i++)
- {
- color prevCol = imgCopy.pixels[i];
- color newCol = color(hue(prevCol)* HueRatio, saturation(prevCol) * SatRatio, brightness(prevCol)*brightRatio);
- if (Toggleinvert)
- {
- colorMode(RGB,255,255,255);
- new_color = color(255-red(new_color), 255-green(new_color), 255-blue(new_color));
- }
- imgCopy.pixels[i] = newCol;
- }
- imgCopy.updatePixels(); //updates the pixel
- if (ToggleFilter) {
- filter();
- }
- else {
- image(imgCopy, 0, 0, width, height); //draws the pixels
- }
- }
- void filter() {
- img.loadPixels();
- float filterRatio = (float)filter1;
- for ( int c = 0; c < cols; c++) {
- // Begin loop for rows
- for ( int r = 0; r < rows; r++) {
- colorMode(HSB,255,255,255);
- int x = c*cellsize + cellsize/2; // x position
- int y = r*cellsize + cellsize/2; // y position
- int loc = x + y*width; // Pixel array location
- color b = img.pixels[loc]; // Grab the color
- // Calculate a z position as a function of mouseX and pixel brightness
- float z = (filterRatio/(float)width) * brightness(img.pixels[loc]) - 100.0;
- // Translate to the location, set fill and stroke, and draw the rect
- pushMatrix();
- translate(x,y,z);
- fill(b);
- noStroke();
- rectMode(CENTER);
- rect(0,0,cellsize,cellsize);
- popMatrix();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement