We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › amorphous blob generator
Page Index Toggle Pages: 1
amorphous blob generator (Read 1662 times)
amorphous blob generator
Oct 15th, 2005, 6:32pm
 
Am making a drawing machine for a thesis. I want it to make vaguely round blob polygons. No bezier curves - I want to use a polygon detection algorithm. I've got a method worked out of turning round slowly and then cutting off. Exterior angles should add up to TWO_PI, that's when we stop turning.

Problem is, the line sometimes over shoots the start or turns in to quickly. Instead of a nice wobbly blob it has a nasty kink in it. I thought of cutting it off if it gets too close to the start but that'd just not nice enough.

Any suggestions?
Code:

Tracer test;
void setup(){
size(400,400);
test = new Tracer();
}
void draw(){
test.draw();
}
void mousePressed(){
test.trace(mouseX,mouseY);
}
class Tracer{
Polygon [] polys;
boolean write;
float theta,radian;
Tracer(){
polys = new Polygon[1];
polys[0] = new Polygon(random(width),random(height));
}
void trace(float x, float y){
float theta = random(TWO_PI);
float circum = TWO_PI-0.5;
float xStart = x;
float yStart = y;
boolean write = true;
int num;
if (polys.length < 2)
num = 0;
else{
newPolygon(polys[polys.length-1]);
num = polys.length-1;
}
polys[num] = new Polygon(x,y);
float turn = 0.0;

while(turn < circum){
x += cos(theta+turn)*random(4,8);
y += sin(theta+turn)*random(4,8);
polys[num].addVertex(x,y);
turn += random(0.4);
if(turn > PI && dist(x,y,xStart,yStart) < 10) break;
}
}
void draw(){
for(int i = 0; i < polys.length; i++){
polys[i].draw();
}
}
void newPolygon(Polygon newPolys) {
Polygon [] temp = new Polygon[polys.length + 1];
System.arraycopy(polys, 0, temp, 0, polys.length);
temp[polys.length] = newPolys;
polys = temp;
}
}
class Polygon{
float [] x,y;
Polygon (float [] points){
x = new float[points.length/2];
y = new float[points.length/2];
for(int i = 0; i < points.length; i+=2){
x[i/2] = points[i];
y[i/2] = points[i+1];
}
}
Polygon (float startX, float startY){
x = new float[1];
y = new float[1];
x[0] = startX;
y[0] = startY;
}
void addVertex(float addX, float addY){
x = append(x, addX);
y = append(y, addY);
}
void draw(){
beginShape(POLYGON);
for(int i = 0; i < x.length; i++)
vertex(x[i],y[i]);
endShape();
}
}
Page Index Toggle Pages: 1