xxxxxxxxxx
scp = {x:250, y:250, mag:0.0};
things = [ scp,
//{x:100.0, y:100.0, mag:1.0},
//{x:150.0, y:100.0, mag:1.0},
//{x:150.0, y:150.0, mag:1.0},
//{x:100.0, y:150.0, mag:1.0}
];
void setup() {
size(500, 500);
colorMode(RGB, 1.0);
background(0);
for( let i = 0; i < 25; i++){
things.push({x:random(width), y:random(height), mag:random(5)});
}
}
function paintproc(x, y, z){
stroke(constrain(z,0,1));
point(x,y);
}
radstep = 0.0;
done = false;
void draw() {
for(let i = 0; i < 20; i++){
if(radstep <= height && radstep <= width) {
paintI(0, radstep, 1, paintproc);
paintI(width, height-radstep, 1, paintproc);
paintI(radstep, 0, 1, paintproc);
paintI(width-radstep, height, 1, paintproc);
radstep+= 0.5;
done = false;
} else {
done = true;
}
}
noStroke();
for(let i = 0; i < things.length; i++){
let thing = things[i];
if(I(thing.x, thing.y, 1) > 1){
fill(0,0.5*thing.mag/5 + 0.5,0);
} else {
fill(0.5*thing.mag/5 + 0.5,0,0);
}
ellipse(thing.x, thing.y, 3, 3);
}
fill(0,0,1);
ellipse(scp.x, scp.y, 3, 3);
}
void mouseDragged() {
if(done)
for( let i = 0; i < things.length; i++) {
if(sq(pmouseX - things[i].x) + sq(pmouseY - things[i].y) < 16){
things[i].x += mouseX - pmouseX;
things[i].y += mouseY - pmouseY;
break;
}
}
}
void mouseReleased(){
radstep = 0;
background(0);
}
scale = 0.05;
c2 = 6.152 * scale;
c3 = 0.468 * scale * scale;
function p(x, y) {
var total = 0;
for( let i = 0; i < things.length; i++) {
let thing = things[i];
total += log(thing.mag + 1) * exp( -c3 * (sq(thing.x - x) + sq(thing.y - y)));
}
return c2 * total;
}
function I(xf, yf, ds) {
var x = scp.x;
var y = scp.y;
var s = 0;
var sf = dist(x,y,xf,yf);
var steps = sf / ds;
var dx = (xf-x) / steps;
var dy = (yf-y) / steps;
var total = 0;
var lastp = p(x, y);
var thisp = lastp;
while(s < sf){
s += ds;
x += dx;
y += dy;
lastp = thisp;
thisp = p(x, y);
if(thisp < lastp){
total += thisp;
}
}
return total;
}
function paintI(xf, yf, ds, paintproc) {
var x = scp.x;
var y = scp.y;
var s = 0;
var sf = dist(x,y,xf,yf);
var steps = sf / ds;
var dx = (xf-x) / steps;
var dy = (yf-y) / steps;
var total = 1;
var lastp = p(x, y);
var thisp = lastp;
while(s < sf){
s += ds;
x += dx;
y += dy;
lastp = thisp;
thisp = p(x, y);
if(thisp < lastp){
total -= thisp;
}
paintproc(x, y, total);
if(total <= 0) break;
}
}