Bill Hsu
YaBB Newbies
Offline
Posts: 9
more blobs and splatters
Sep 23rd , 2009, 4:57pm
I posted a while back asking for ways to make fluid-y blobs and splatter shapes. Had some time recently to play with this some more, so here's another try, and one more in the followup. Would appreciate comments, thanks! In my original post, I played with Perlin noise contours. The results were a bit hard to control (difficult to center, may get lots of blobs etc). Here's another approach with Perlin noise. I'm basically tracing a circle, but using Perlin noise to modulate the radius. When I get close to the end of the circle, I crossfade back to the starting point. This gets more controllable results (always one blob, centered correctly). But the shapes are not that fluid-like, if that's what you want. In the Blob constructor class, there are two control parameters to adjust the blob: maxRadiusDev is the maximum % deviation from the specified radius noiseInc is the Perlin noise index increment (increase to make the blob edges more jagged) Code follows... Bill // Make irregular blobs // hit space to get new blob Blob myBlob; void setup() { size(200, 200); myBlob = new Blob(400, 50., width/2, height/2); } void draw() { smooth(); background(255); myBlob.display(); } void keyPressed() { if (key == ' ') myBlob = new Blob(400, 50., width/2, height/2); } class Blob { int [] x; int [] y; float radius; int centerX, centerY; Blob(int numVertex, float rad, int cX, int cY) { radius = rad; centerX = cX; centerY = cY; x = new int[numVertex]; y = new int[numVertex]; float angle = 0; float deltaAngle = TWO_PI / numVertex; float noiseSample = random(0, 100); // Perlin noise index float noiseInc = .02; // Perlin noise inc float maxRadiusDev = .2; // max radius deviation in percent float radFactor; float zRad; radFactor = 1 + maxRadiusDev * (1 - 2 * noise(noiseSample)); x[0] = centerX + (int) (radFactor * radius * cos(angle)); y[0] = centerY + (int) (radFactor * radius * sin(angle)); zRad = radFactor * radius; angle += deltaAngle; noiseSample += noiseInc; int i; for (i=1; i<(int) (.9 * numVertex); i++) { radFactor = 1 + maxRadiusDev * (1 - 2 * noise(noiseSample)); x[i] = centerX + (int) (radFactor * radius * cos(angle)); y[i] = centerY + (int) (radFactor * radius * sin(angle)); angle += deltaAngle; noiseSample += noiseInc; } int startI = i; int remInterval = numVertex - i; float rx = x[i-1] - centerX; float ry = y[i-1] - centerY; float lastRad = sqrt(rx * rx + ry * ry); float deltaRad = zRad - lastRad; println("last x y " + x[i-1] + " " + y[i-1] + " " + lastRad + " " + zRad + " " + remInterval ); for (; i<numVertex; i++) { float frac = (i-startI + 1) * deltaRad / remInterval; x[i] = centerX + (int) ((lastRad + (i-startI + 1) * deltaRad / remInterval) * cos(angle)); y[i] = centerY + (int) ((lastRad + (i-startI + 1) * deltaRad / remInterval) * sin(angle)); angle += deltaAngle; println("x y " + x[i] + " " + y[i]); } } void display() { fill(0); beginShape(); curveVertex(x[0], y[0]); for (int i=0; i<x.length; i++) { curveVertex(x[i], y[i]); } curveVertex(x[x.length-1], y[y.length-1]); endShape(); } }