Skip to content

Instantly share code, notes, and snippets.

@Bleuje
Created August 19, 2017 17:32
Show Gist options
  • Save Bleuje/3a6fa8af6f2bf65cab9c752061b3e371 to your computer and use it in GitHub Desktop.
Save Bleuje/3a6fa8af6f2bf65cab9c752061b3e371 to your computer and use it in GitHub Desktop.
float ease(float p, float g) {
if (p < 0.5)
return 0.5 * pow(2*p, g);
else
return 1 - 0.5 * pow(2*(1 - p), g);
}
class Center{
/*
float rad = height/3*sqrt(random(1));
float theta = random(TWO_PI);
float x = width/2 + rad*cos(theta);
float y = height/2 + rad*sin(theta);*/
float bb = 3;
float x = random(border*bb,width-border*bb);
float y = random(border*bb,height-border*bb);
Center(float pos){
x = width/2;
y = pos;
}
float fact = random(3,3);
void show(){
stroke(255,0,0);
strokeWeight(3);
point(x,y);
}
}
int N = 1;
Center[] array = new Center[N];
float epsilon = 1e-4;
/*
float field(float x,float y){
float amount = 1500;
float sum = 0;
for(int i = 0;i<N;i++){
float distance = dist(x,y,array[i].x,array[i].y);
float intensity = 1/(distance+epsilon+15);
sum += array[i].fact*intensity*amount;
}
return sum;
}*/
float field(float x,float y){
float amount = 170;
float sum = 0;
for(int i = 0;i<N;i++){
float distance = dist(x,y,array[i].x,array[i].y);
float intensity = constrain(map(distance,0,width,1,0),0,1);
intensity = pow(intensity,8);
sum += array[i].fact*intensity*amount - 0.00015*pow(y,2.5);
}
return sum;
}
void setup(){
size(500,800);
background(0);
for(int i=0;i<N;i++){
array[i] = new Center(height/2);
}
}
int numFrames = 15;
int border = 50;
void draw(){
background(0);
float t = 1.0*frameCount/numFrames%1;
/*
for(int i=0;i<N;i++){
array[i].show();
}*/
for(int i = border;i<width-border;i++){
for(int j=border;j<height-border;j++){
float phase = 0.1*field(i,j);
float col = ease(pow(map(sin(phase + TWO_PI*t),-1,1,0,1),1),5);
col *= 255;
stroke(col);
point(i,j);
}
}
/*
int ni = 50;
for(int i=0;i<ni;i++){
for(int j=0;j<ni;j++){
float x = map(i,0,ni-1,0,width);
float y = map(j,0,ni-1,0,height);
float res = field(x,y);
stroke(res);
strokeWeight(1);
point(x,y);
}
}*/
noFill();
stroke(255);
strokeWeight(1);
rect(border,border,width-2*border,height-2*border);
if(frameCount<=numFrames){
saveFrame("fr###.png");
}
if(frameCount==numFrames){
println("finished");
stop();
}
/*
if(frameCount==1000){
saveFrame("e###.png");
stop();
println("finished");
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment