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 & HelpSyntax Questions › growing random direction line
Page Index Toggle Pages: 1
growing random direction line (Read 602 times)
growing random direction line
Jun 5th, 2009, 2:14pm
 
hey, im trying to do some growing lines that go in random directions and i began trying to do one .

so i thought i would programme a float that would be a noise and then increment it with 0.01  and put something like:
float x2 = initial x value;
float y2 = initial y value;
float x = noise();
float y = noise();
x += incrementFloat;
y += incrementFloat;
line(x2,y2,x,y);

and this didn't work.... can someone tell me why?
but here is my code a little more complete....
line(
Code:


float xplus = 0.01;
float yplus = 0.01;

float xx = random(0, 0.05);
float yy = random(0, 10);




void setup(){
size(595,842);

smooth();

frameRate(60);
}

void draw(){

float x = noise(xx)*width;
float y = noise(yy)*height;
float r = random(100,200);
float g = random(100,200);
float b = random(100,200);
float a = random(100,200);


xx += xplus;
yy += yplus;






float clr1 = random(255);
float clr2 = random(height);
float siZe = random(40);
float xp = noise(20,40);
fill(0,0,clr1,clr1);

line(x,y,y,x);


}

Re: growing random direction line
Reply #1 - Jun 5th, 2009, 6:55pm
 
Im mot sure if i really understood what you are trying to do, maybe explain how it should behave, look etc.

but thats what i quickly did.

float x1 = 300;
float y1 = 400;

void setup(){
size(595,842);
smooth();
}

void draw(){
float x2 = x1 + random(-10,10);
float y2 = y1 + random(-10,10);

line(x1,y1,x2,y2);

x1 = x2;
y1 = y2;
 }


its more or less brownian Motion i would say
Re: growing random direction line
Reply #2 - Jun 6th, 2009, 7:07am
 
well, that's really cool but not quite that! what i want is actually preety normal to see.... its probably how you would do something like http://www.flickr.com/photos/autologous/3572082288/in/pool-generatorx

or
http://www.flickr.com/photos/autologous/3590221929/in/pool-generatorx besides the fact that in these examples there are a lot of lines and i only want one!
Re: growing random direction line
Reply #3 - Jun 7th, 2009, 9:53pm
 
I am working on something kinda like that.

Here is my version:

Code:

float x; // the current position
float y;

float px; // "previous" position
float py;

float vel;
float dir;
// here you declare the speed as a pair of
// direction and absolute speeed, instead of
// declaring each component on x and y axises
// that way you have better control over the
// direction of movement.


void setup(){
 size(400,400);
 stroke(0);
 background(255);
 smooth();
 frameRate(30);

 x=y=px=py=200;
 // at first the previous position is equal
 // to the current

 vel = random(5);  
 dir = random(360);
 // the direction is given in degrees
}

void draw(){
 px = x;
 py = y;
 x+= cos(radians(dir))*vel;
 y+= sin(radians(dir))*vel;
 //this is trigonometry to convert the
 //speed into x and y components

 stroke(0);
 line(px,py,x,y);

 dir+=random(-30,30);

}

Re: growing random direction line
Reply #4 - Jun 8th, 2009, 4:23am
 
thanks so much man!
Page Index Toggle Pages: 1