Quote:What I'm struggling with is attempting to have the lines/particles originate in random dark areas of the image.
i guess. if you think it doesn't work properly at the moment maybe its because of this
int(random(darkAreas.pixels[i]))
when you create the particles.
i don't think that makes any sense, because you dont get any x,y coordinates there.
you can save the darkPoint in an ArrayList
shuffle them and then give them for the particles later. sorry for my english
i mean it like this:
Code:
PImage face;
// PImage darkAreas;
p p[];
ArrayList darkPoints;
void setup(){
size(509,800,P2D);
smooth();
face = loadImage("face.jpg");
image(face, 0, 0,width,height); // img, x, y, width, height
// darkAreas = createImage(face.width, face.height, RGB);
ArrayList darkPoints= new ArrayList();
float threshold = 10;
loadPixels();
// darkAreas.loadPixels();
for (int x=0; x < width; x++) {
for (int y=0; y < height; y++){
int loc = x + y*width;
if (brightness(pixels[loc]) < threshold) { //???
// darkAreas.pixels[loc] = color(0);
darkPoints.add(new Point(x,y));
}
}
}
Collections.shuffle(darkPoints);
p=new p[100]; //number of particles
for(int i=0; i<p.length; i++)p[i]=new p(i/1.0, ((Point)darkPoints.get(i)).x, ((Point)darkPoints.get(i)).y);
}
void draw(){
//frameRate(30);
//image(face, 0, 0); // img, x, y, width, height
stroke(255, 253, 235);
for(int i=0; i<p.length; i++) p[i].update();//render particles
}
void mousePressed() {
image(face, 0, 0); // img, x, y, width, height
}
class p {
float id,x,y,xp,yp,s,d;
public p(float _id, float _x, float _y) {
id=_id;
x=xp=_x;
y=yp=_y;
s=random(1,10); // SPEED (orig. 2,7)///////////////////////
}
void update(){
id+=0.01;
d=(noise(id,x/mouseY,y/mouseY)+0.5)*mouseY; //original 0.5
x+=cos(radians(d))*s;
y+=sin(radians(d))*s;
if(x<-10) x=xp=width+10;//offscreen rewind
if(x>width+100)x=xp=-10;
if(y<-10) y=yp=height+10;
if(y>height+10)y=yp=-10;
stroke(10);
line(xp,yp,x,y);
xp=x;
yp=y;
}
}
i don't know that image you use. maybe you can post it.
you dont need loadpixels for images. i need it here because i used an image that ha not the size as the frame and had to scale it. i rhink you can figure it out.
ra