process[learn]ing


package processingutils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import processing.core.PApplet;
import processing.core.PImage;

public class ImageFilterSquares extends PApplet {
	
	private static final int GRIDSIZE = 20;
	
	private PImage image = loadImage(
			"http://4.bp.blogspot.com/-JJ4NTVYmek4/Udd76IMooOI/AAAAAAAAGJw/ELjbtfZuqQU/s1600/IMG_5534v2crop.jpg");	
	private List<PImage> squares = new ArrayList<PImage>();
	
	private int squareSize = image.width / GRIDSIZE;
	
	private final Boolean rotationOn = Boolean.FALSE;
	
	@Override
	public void setup() {
		size(image.width, image.height);
		background(255);
		generateSquares();
		frameRate(1);
		if(rotationOn) {
			imageMode(CENTER);
		}
	}
	
	@Override
	public void draw() {
		int imageIndex = 0;
		for(int x = 0; x < image.width; x += squareSize) {
			for(int y = 0; y < image.height; y += squareSize) {
				pushMatrix();
				translate(x, y);
				if(rotationOn) {
					rotate(getRandomRotation());
				}
				image(squares.get(imageIndex++), 0, 0);
				popMatrix();
			}
		}
		saveFrame("squares" + (int) random(1000000) + ".png");
		noLoop();
	}
	
	private void generateSquares() {
		for(int x = 0; x < image.width; x += squareSize) {
			for(int y = 0; y < image.height; y += squareSize) {
				PImage square = new PImage(squareSize, squareSize);
				square.copy(image, x, y, squareSize, squareSize, 0, 0, squareSize, squareSize);
				
				squares.add(square);
			}
		}
		Collections.shuffle(squares);
	}
	
	private float getRandomRotation() {
		float rand = random(1);
		if(rand < 0.25) {
			return 0.f;
		}
		else if(rand >= 0.25 && rand < 0.5) {
			return PI / 2;
		}
		else if(rand >= 0.5 && rand < 0.75) {
			return PI;
		}
		else {
			return 3 * PI / 2;
		}
	}
	
	public static void main(String[] args) {
		PApplet.main("processingutils.ImageFilterSquares");
	}
	
}
package processingutils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import processing.core.PApplet;
import processing.core.PImage;

public class ImageFilterSquares extends PApplet {
	
	private static final int GRIDSIZE = 20;
	
	private PImage image = loadImage(
			"http://4.bp.blogspot.com/-JJ4NTVYmek4/Udd76IMooOI/AAAAAAAAGJw/ELjbtfZuqQU/s1600/IMG_5534v2crop.jpg");	
	private List<PImage> squares = new ArrayList<PImage>();
	
	private int squareSize = image.width / GRIDSIZE;
	
	private final Boolean rotationOn = Boolean.FALSE;
	
	@Override
	public void setup() {
		size(image.width, image.height);
		background(255);
		generateSquares();
		frameRate(1);
		if(rotationOn) {
			imageMode(CENTER);
		}
	}
	
	@Override
	public void draw() {
		int imageIndex = 0;
		for(int x = 0; x < image.width; x += squareSize) {
			for(int y = 0; y < image.height; y += squareSize) {
				pushMatrix();
				translate(x, y);
				if(rotationOn) {
					rotate(getRandomRotation());
				}
				image(squares.get(imageIndex++), 0, 0);
				popMatrix();
			}
		}
		saveFrame("squares" + (int) random(1000000) + ".png");
		noLoop();
	}
	
	private void generateSquares() {
		for(int x = 0; x < image.width; x += squareSize) {
			for(int y = 0; y < image.height; y += squareSize) {
				PImage square = new PImage(squareSize, squareSize);
				square.copy(image, x, y, squareSize, squareSize, 0, 0, squareSize, squareSize);
				
				squares.add(square);
			}
		}
		Collections.shuffle(squares);
	}
	
	private float getRandomRotation() {
		float rand = random(1);
		if(rand < 0.25) {
			return 0.f;
		}
		else if(rand >= 0.25 && rand < 0.5) {
			return PI / 2;
		}
		else if(rand >= 0.5 && rand < 0.75) {
			return PI;
		}
		else {
			return 3 * PI / 2;
		}
	}
	
	public static void main(String[] args) {
		PApplet.main("processingutils.ImageFilterSquares");
	}
	
}
  1. masademateriasinforma reblogged this from sharethelobe
  2. sharethelobe reblogged this from thingfoundry
  3. russellbert reblogged this from fyprocessing
  4. tutoprocessing reblogged this from fyprocessing
  5. transezual reblogged this from fyprocessing
  6. nathaliaverli reblogged this from fyprocessing
  7. zabotage reblogged this from fyprocessing
  8. cyanpup reblogged this from fyprocessing
  9. cuddles-xu reblogged this from fyprocessing
  10. fyprocessing reblogged this from jtoprocessing
  11. brainwavy reblogged this from thingfoundry and added:
    Neat.
  12. jtoprocessing posted this