/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.fKgR7loWYb$/rev.660
*
* authors:
* Hamid
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
/*
This sketch builds on a prior work, "Blobs ", created by Hamid
http://studio.sketchpad.cc/sp/pad/view/ro.9N6178qQHPj5u/rev.12
*/
// RHM Name Coordinates //////////////////////////////////////////////////////
int Vx1 =[[6,1],[5,1],[5,6],[4,3],[3,3],[2,1],[2,2],[2,3],[3,4],[2,5],[1,6],[5,6]];
int Vy1 =[[6,6],[5,5],[5,7],[4,6],[3,5],[2,2],[4,2],[5,3],[4,4],[4,5],[4,6],[6,6]];
float VPts=[[2,4]];
float VDots=[[3.5,4.5],[3.5,3.5]];
var msg = "Hi Blobs";
int numBlobs = Vx1.length;
BlobPx = new int[numBlobs];
BlobPy = new int[numBlobs];
BlobDx = new float [numBlobs];
BlobDy = new float [numBlobs];
for (var i=0; i<numBlobs;i++)
{BlobPx[i] = int(10*Vx1[i][0]);
BlobPy[i] = int(10*Vx1[i][1]);
BlobDx[i] = 1;
BlobDy[i] = 1;
}
//int numBlobs = 3;
//int[] BlobPx = { 0, 90, 120 };
//int[] BlobPy = { 40, 120, 45 };
// Movement vector for each blob
//int[] BlobDx = { 1, 0.8, 0.6, 1, 0.8, 0.6,1, 0.8, 0.6,1, 0.8, 0.6};
//int[] BlobDy = { 0, 1, -0.3,0, 1, -0.3,0, 1, -0.3,0, 1, -0.3 };
int[] BlobDx = { 1, 1,1,1,1,1,0,0,0,0,0,0};
int[] BlobDy = { 0,0,0,0,0,0,1, 1,1,1,1,1 };
PGraphics pg;
int[][] vy,vx;
String name = "metaball";
void setup() {
size(200, 200);
pg = createGraphics(100, 100);
vy = new int[numBlobs][pg.height];
vx = new int[numBlobs][pg.width];
frameRate(30);
}
void draw() {
for (int i=0; i<numBlobs; ++i) {
BlobPx[i]+=BlobDx[i];
BlobPy[i]+=BlobDy[i];
///////////////////////////////////////////
// Output into a buffered image for reuse
pg.beginDraw();
pg.loadPixels();
//////////////////////////////////////////////
// bounce between Blob i limits ///////////////////////////////////////////
//Horizontally or Vertically
if(Vx1[i][0]==Vy1[i][0])
{
msg = "H " + BlobPx[i] + " - " + Vx1[i][1] + "-" + Vy1[i][1] + "dx/dy " + BlobDx[i] +"/" + BlobDy[i];
BlobDy[i] =0;
if (BlobPx[i] < 10*Vx1[i][1]) { BlobDx[i] = 1;}
if (BlobPx[i] > 10*Vy1[i][1]) {BlobDx[i] = -1;}
}
else
{
msg = "V " + BlobPx[i] + " - " + Vx1[i][0] + "-" + Vy1[i][0] + "dx/dy " + BlobDx[i] + "/" + BlobDy[i];
BlobDx[i] =0;
if (BlobPy[i] < 10*Vx1[i][0]) {BlobDy[i] = 1;}
if(BlobPy[i] > 10*Vy1[i][0]) {BlobDy[i]=-1;}
}
////////////////////////////////////////////////
//println(msg+"..."+i);
for (int x = 0; x < pg.width; x++) {
vx[i][x] = int(sq(BlobPx[i]-x));
}
for (int y = 0; y < pg.height; y++) {
vy[i][y] = int(sq(BlobPy[i]-y));
}
}
//////////////////////////////////////////////
// Output into a buffered image for reuse
//////////////////////////////////////////////
for (int y = 0; y < pg.height; y++) {
for (int x = 0; x < pg.width; x++) {
int m = 1;
for (int i = 0; i < numBlobs; i++) {
// Increase this number to make your blobs bigger
m += 3000/(vy[i][y] + vx[i][x]+1);
}
pg.pixels[x+y*pg.width] = color( 0,m+x, (x+m+y)/2);
}
}
pg.updatePixels();
pg.endDraw();
// Display the results
image(pg, 0, 0, width, height);
}