Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage img;
- //float nz;
- void setup() {
- size(500, 540);
- img = loadImage("photo2.jpg");
- // surface.setResizable(true);
- // surface.setSize(img.width, img.height);
- }
- void draw() {
- // try uncommenting the following lines to get different effects
- //image(img, 0, 0);
- //distortImage();
- //stampImage();
- //colorCircles();
- //dripColorManu();
- //dripColorAuto();
- //feedbackloop();
- //feedbackloop2();
- //colorLines();
- //filterStuff();
- //filterStuff2();
- }
- void distortImage() {
- //background(0);
- // make image semi-transparent with tint(255,x);
- tint(255, 50);
- // use mouse positions as the width and height of the image
- image(img, 0, 0, mouseX, mouseY);
- }
- void stampImage() {
- img.resize(width/2, height/2);
- // make the center of the image the starting point
- //imageMode(CENTER);
- //tint(255, 50);
- // only do a certain thing if the mouse is pressed
- //if (mousePressed) {
- image(img, mouseX, mouseY);
- //}
- }
- void colorCircles() {
- // choose a random size for the circle
- float sz = random(5, 25);
- // get the color of the pixel where the mouse is
- color c = img.get(mouseX, mouseY);
- fill(c);
- stroke(255, 150);
- if (mousePressed) {
- ellipse(mouseX, mouseY, sz, sz);
- }
- }
- void dripColorManu() {
- color c = img.get(mouseX, mouseY );
- fill(c, random(100, 150));
- noStroke();
- if (mousePressed) {
- // paint 'drips' of varying sizes
- rect(mouseX, mouseY, random(1, 5), random(5, 100), 3);
- }
- }
- void dripColorAuto() {
- int x = (int) random(width);
- int y = (int) random(height);
- color c = img.get(x, y );
- fill(c, random(100, 150));
- noStroke();
- rect(x, y, random(1, 10), random(5, 100), 3);
- }
- void feedbackloop() {
- // [slices]
- // slow the sketch down to better see what's going on
- frameRate(15);
- // determine the location to cut from
- int x1 = 0;
- int y1 = (int) random(height);
- // determine the offset for the paste
- int y2 = int(y1 + random(-7, 7));
- int x2 = int(random(-5, 5));
- // the height of the slice should vary
- int w = width;
- int h = (int) random(5, 10);
- // copy the slice to its new location
- copy(x1, y1, w, h, x2, y2, w, h);
- }
- void feedbackloop2() {
- // [squares]
- frameRate(15);
- // determine a random location to cut from
- int x1 = (int) random(width);
- int y1 = (int) random(height);
- // determine the offset for the paste
- int x2 = int(x1 + random(-10, 10));
- int y2 = int(y1 + random(-10, 10));
- // we're copying squares here
- int w = 100;
- int h = 100;
- // copy the square to the new place
- copy(x1, y1, w, h, x2, y2, w, h);
- }
- void colorLines() {
- // create horizontal lines starting in the middle of the image, using the color of the corresponding pixel
- image(img, 0, 0);
- // do the following for each horizontal line (of the image)
- for (int y = 0; y <height; y++) {
- // position x at the middle of the width
- int x = width/2;
- // get the color of that pixel
- color col = get(x, y);
- // map the length of that line to the horizontal position of the mouse
- float lineLength = map(mouseX, 0, width, -300, 300);
- // map the transparency of that line to the vertical position of the mouse
- float alpha = map(mouseY, 0, height, 100, 255);
- // apply that transparency to that line
- stroke(col, alpha);
- // draw that line
- line(x, y, x+lineLength, y);
- // add a twist to it
- //float offSetY = map(y, 0, height, lineLength, -lineLenght);
- //line(x, y, x+offSetY, y);
- }
- }
- void filterStuff() {
- image(img, 0, 0);
- // change color mode from Red Green Blue to Hue Saturation Brightness
- colorMode(HSB);
- // load the pixels of the image
- loadPixels();
- // loop through all the pixels
- for (int i=0; i<pixels.length; i++) {
- // get the hue, saturation and brightness of each pixel
- float h = hue(pixels[i]);
- float s = saturation(pixels[i]);
- float b = brightness(pixels[i]);
- // modify the color information of the pixel
- //if (i>pixels.length/2)
- pixels[i] = color(h, 255-s, b);
- }
- // update the pixels to see the result
- updatePixels();
- }
- void filterStuff2() {
- // noise example just to show what's possible
- image(img, 0, 0);
- colorMode(HSB);
- loadPixels();
- float nx = 0;
- float ny = 0;
- for (int x=0; x<width; x++) {
- ny = 0;
- for (int y=0; y<height; y++) {
- float ns = noise(nx, ny, nz);
- float h = hue(img.get(x, y));
- float s = saturation(img.get(x, y));
- float b = brightness(img.get(x, y));
- if (ns > 0.5) pixels[y*width+x] = color(h, 255-s, b);
- ny += 0.005;
- }
- nx += 0.005;
- }
- updatePixels();
- nz += 0.007;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement