Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage img;
- ArrayList pieces;
- float x, y;
- float incr;
- color col;
- int counter = 0;
- void setup() {
- img = loadImage("http://i.imgur.com/GypezS6.jpg");
- size(img.width, img.height);
- img.loadPixels();
- rectMode(CENTER);
- pieces = new ArrayList();
- incr = 2;
- for (int i = 0; i<width; i += incr) {
- for (int j = 0; j < height; j += incr) {
- x = i + incr/2;
- y = j + incr/2;
- col = img.pixels[int(y)*width+int(x)];
- Piece piece = new Piece(x, y, col);
- pieces.add(piece);
- }
- }
- }
- void draw() {
- background(0);
- for (int i = 0; i < pieces.size(); i++) {
- Piece p = (Piece) pieces.get(i);
- p.run();
- }
- }
- class Piece {
- float x, y;
- float incr_ex = 0.01;
- color c;
- PVector s;
- Piece(float _x, float _y, color _col) {
- x = _x;
- y = _y;
- c = _col;
- s = new PVector(random(-2, 2), random(-2, 2));
- }
- void run() {
- display();
- if (frameCount > 75) {
- explode();
- }
- }
- void explode() {
- x += s.x;
- y += s.y;
- }
- void display() {
- fill(c);
- noStroke();
- rect(x, y, incr, incr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement