Hi,
I've a small PImage that I want to break apart the pixels and scatter them in all directions randomly. I haven't gotten to the latter stages yet but I'm having difficulty with the immediate stages.
As the original pixels go to the PImage edge, I created a second PImage that's twice the size. I'm trying to copy the original pixels into the centre of this, leaving blank edges around it for random scattering when I put in the appropriate code.
I can get the pixels to start in the correct location of the second PImage but I can't limit where each X line ends. Instead, the pixels go to the edge of the larger PImage. Any ideas?
Code:
int index;
float xpos;
float ypos;
float dartSpeed;
PImage dart;
PImage fuzzyDart;
color pink = color(255, 102, 204);
void setup()
{
size(500, 500);
background(200);
frameRate(25);
dart= loadImage("dart.png");
fuzzyDart = createImage(dart.width*2, dart.height*2, ARGB);
xpos = 0;
ypos = 0;
dartSpeed = 3;
}
void draw()
{
background(200);
// draw bg graphics
stroke(90);
for (int sleeperNumber = 0; sleeperNumber < height/2; sleeperNumber++) {
line(-11 + (sleeperNumber * 4), sleeperNumber * 4, -2 + (sleeperNumber * 4) + 3, sleeperNumber * 4);
}
stroke(120);
line(-2, 0, width - 2, height);
line(-8, 0, width - 8, height);
// draw darts
dart.loadPixels();
index=0;
for(int x = 1; x < dart.width -1; x++) {
for(int y = 1; y < dart.height -1; y++) {
if (y <= x) {
//bottom left side of dart picture
fuzzyDart.pixels[((fuzzyDart.width/2) * (fuzzyDart.height/2)) - ((dart.width/2) * (dart.height/2)) +index] = dart.pixels[((x-1)*dart.width) + (y-1)];
} else {
//top right side of dart picture
fuzzyDart.pixels[((fuzzyDart.width/2) * (fuzzyDart.height/2)) - ((dart.width/2) * (dart.height/2)) +index] = dart.pixels[((x-1)*dart.width) + (y-1)];
}
index++;
}
}
fuzzyDart.updatePixels();
dartSpeed = mouseX / 30;
image(fuzzyDart, xpos, ypos);
xpos = (xpos + dartSpeed);
ypos = ypos + dartSpeed;
if (xpos > width) {
xpos = -120;
ypos = -120;
}
}