Loading...
Logo
Processing Forum
Hi there,

I'm trying to load a series of randomly repeating images into a type mask, but am having trouble doing it.  The end result should look like this:



But so far, I can only get the pieces to slide across the screen behind the mask.  Can anyone help me with this?  I'm a beginner and I'm stuck...  My code so far is:

http://pastie.org/1041757

ArrayList pieces;
PImage maskImage;

int totalPieces = 9;
int counter = 0;
int counterThreshold = 1000;

class Piece{
  PImage img;
  float x, y;
  float xDir, yDir;
  Piece(String path)
  {
    img = loadImage(path);
    x = random(1)*width;
    y = random(1)*height;
    xDir = random(1)*2+0.5;         // change this to a fix number like xDir = 3; will fix the speed

    if(random(1)>0.5)
      yDir = random(1);
    else
      yDir = random(1)*(-1); 
  }
}

void setup(){
 
  size(800,600);
  background(255);
 
  maskImage = loadImage("mask.png");
 
  pieces = new ArrayList();
  for(int i=0; i<totalPieces*100; i++){
    String imgPath = "p"+Integer.toString( i%totalPieces+1 )+".png";
    pieces.add(new Piece(imgPath));
  }
}

void draw(){
 
  background(255);
 
  for(int i=0; i<pieces.size(); i++){
    Piece piece = (Piece)pieces.get(i);
    piece.x = piece.x + piece.xDir;
    image(piece.img, piece.x, piece.y);
  }
  image(maskImage,0,0);
 
  if(counter>counterThreshold){
    for(int j=0; j<pieces.size(); j++){
      Piece piece = (Piece)pieces.get(j);
      piece.x = 50;
    }
    counter = 0;
  }
  counter++;
 
}

Replies(6)

I wouldnt use a mask actually. As you are using an image anyway I would recommend to read the image pixel by pixel and replace every white pixel with one of your elements. For example. if you have a 200x50 create an image with 200x50 pixels and use a non anti aliased font to write your text.

Then use get(x,y); or the pixels array in a for loop to check for the color. If the color is white. create an element in your matrix
Hope that makes some sense. .


thanks, cedric.  i'll give it a shot!
Good Luck :) Just come back if it doesnt work.

I haven't been able to figure the code out.  Sorry...I'm pretty new at this.

If you can show me how it should look, I'll try plugging it in with my files....otherwise, I'm not so sure.
i will give you a code example later that day. But you can create a shape and a b/w source image in the meantime for me to use.
I am interested in this too