/*bursting attractor
created with processing 0135
by rce12
- click to reset
fun with PImage, i was create them to draws the mosaics. then,
particles strikes back on it. add a recursion flow for create it
double shots to mesmerizely that attractor.
*/
int nmb=1000;
abstractor[] painters;
flowburst burst;
PImage mosaic;
void setup(){
size(500,500);
painters=new abstractor[nmb];
smooth();
//init abstractors
for(int a=0;a<painters.length;a++){
painters[a]=new abstractor();
}
//init flowburst
burst=new flowburst((int)random(2,10));
background(0);
//create mosaics only 1/4 from screen
mosaic=new PImage(width/4,height/4);
}
void draw(){
fill(0,5);
rect(0,0,width,height);
for(int a=0;a<painters.length;a++){
painters[a].interact(4);
painters[a].trail();
}
burst.trail();
//create mosaics
mosaic.copy(g,0,0,width,height,0,0,width/4,height/4);
//mask itself
mosaic.mask(mosaic);
//blend
blend(mosaic,0,0,(width/4)-1,(height/4)-1,0,0,width,height,BLEND);
}
void mousePressed(){
//reset
for(int a=0;a<painters.length;a++){
painters[a]=new abstractor();
}
burst=new flowburst((int)random(2,10));
}
class flowburst{
int mod;
float[] xm;
float[] ym;
float x,y;
flowburst(int mod0){
//construct this
mod=mod0;
xm=new float[mod];
ym=new float[mod];
for(int i=0;i<mod;i++){
xm[i]=random(-1,1);
ym[i]=random(-1,1);
}
}
void trail(){
for(int i=0;i<mod;i++){
x=mod*xm[i];
y=mod*ym[i];
}
}
}
class abstractor{
float x,y,x2,y2,mx,my;
float rad,theta;
float burst_dist;
float inv;
float rd,gr,bl;
color c=color(random(0,255),random(0,255),random(0,255));
float ox,oy,ox2,oy2;
abstractor(){
//construct this
x=random(-1,1);
y=random(-1,1);
x2=random(-1,1);
y2=random(-1,1);
if(random(100)>99){
x2=-x2;
}
if(random(100)>99){
y2=-y2;
}
rad=sqrt(x2*x2+y2*y2);
theta=atan2(x2,y2);
rd=(c>>16)&0xff;
gr=(c>>8)&0xff;
bl=c&0xff;
}
void interact(int lv){
//previously move
ox2=ox;
oy2=oy;
ox=x;
oy=y;
//burst distance
burst_dist=sqrt(sq(burst.x-x)+sq(burst.y-y));
x2=rad*cos(theta+burst_dist);
y2=rad*sin(theta+burst_dist);
//update
rad=sqrt(x2*x2+y2*y2);
theta=atan2(x2,y2);
x+=rad*cos(theta);
y+=rad*sin(theta);
//perform random walk
if(x<0){
x+=random(-1,1);
}else if(x>=random(-1,1)){
x-=random(-1,1);
}
if(y<0){
y+=random(-1,1);
}else if(y>=random(-1,1)){
y-=random(-1,1);
}
//recursive flow
if(lv>1){
lv--;
interact(lv);
}
}
void trail(){
//trail abstractors
stroke(rd,gr,bl,48);
line(x,y,ox2,oy2);
line(width-x,y,width-ox2,oy2);
line(x,height-y,ox2,height-oy2);
line(width-x,height-y,width-ox2,height-oy2);
}
}