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 › Curvy tail with grass leaf shape
Page Index Toggle Pages: 1
Curvy tail with grass leaf shape? (Read 1735 times)
Curvy tail with grass leaf shape?
Jul 27th, 2007, 5:58am
 
Hello everyone, i am trying to make a tail following an object.
The tail shape is looking like grass leaf. I look at some example
of making tails, but those tails are simply line tail, which is not
what i wanted... Did anyonehave some idea on how to do this
kind of tail?

Thanks!
Re: Curvy tail with grass leaf shape?
Reply #1 - Jul 27th, 2007, 7:18am
 
i would do something like this:

make an array to record your movements. you can simply record your position in every frame at the first position in the array and shift older ones, so you always have your last positions. the length of your array will be the length of your tail. you can also add some values to all the positions saved in your array in every frame, this will add some extra motion to your tail. just in case you don't want your tail to just follow exactly the path you have moved your object.

so far you've got points you can connect to a line. you can then change the strokeweight of this line during connecting the points. you'll get a shape that is bigger at the beginning and gets smaller towards the end.
another option is drawing ellipses at every position of your array. if the distance between the ellipses is small enough, you can get a similar shape. this would be better if you run in opengl where you can't have big strokeweights.
the more advanced version to get to the grass-look would be to calculate the outline of the shape you want by adding some decreasing offset to your arraypositions. you then have twice as much points as your arraylength. make a shape of these by connecting them with vertex-calls.

another extra could be an additional dimension, you could add a noise to the z-dimension and use lights to get grass-like shading.
you can also use a PImage to texture that shape with a png of a nice grassleaf. you would have to add two extra parameters with each call to vertex to map the image to the mesh.
hope this helps
Re: Curvy tail with grass leaf shape?
Reply #2 - Jul 27th, 2007, 9:01am
 
Hello, lenny. Thanks for the reply, it's really helpful.Cheesy

I have work out how to do the linear motion of tail. But i still do know how to add some extra motion to make my tail move like some kind of under water tail. I try to use random()..but it just keep shaking very crazy.Are there any good way to make the tail to have some floating motion when the main boday is not moving?

Thanks! Smiley
Re: Curvy tail with grass leaf shape?
Reply #3 - Jul 27th, 2007, 9:16am
 

some kind of underwatertail....
in case you don't know about perlinnoise, check the
processing reference for noise(), it's really great for motion and floating around and things like that.
it's important to feed it with very small and changing values. then it can solve lots of troubles.

maybe something like this:

import processing.opengl.*;

float x,y,t;
float[] xpos=new float[100];
float[] ypos=new float[100];
void setup(){
 size(400,400,OPENGL);
 smooth();
 noStroke();
 x=y=200;
 for(int i=0;i<100;i++){
   xpos[i]=x;
   ypos[i]=y;
 }
}


void draw(){
 background(255);

 //motion
 t=frameCount/200.0;
 x=noise(t,0)*width;
 y=noise(t,1)*height;


 //shift array
 for(int i=1;i<100;i++){
   xpos[i-1]=xpos[i]+(noise(t,4)-0.5)*2.0;
   ypos[i-1]=ypos[i]+(noise(t,5)-0.5)*2.0;
 }
 xpos[99]=x;
 ypos[99]=y;


 //draw tail
 fill(100,255,0);
 beginShape(TRIANGLE_STRIP);
 for(int i=99;i>0;i--){
   vertex(xpos[i],ypos[i]);
   vertex(xpos[i]+i/5.0,ypos[i]);
 }

 endShape();
 fill(0,255,0);
 beginShape(TRIANGLE_STRIP);
 for(int i=99;i>0;i--){
   vertex(xpos[i],ypos[i]);
   vertex(xpos[i]-i/5.0,ypos[i]);
 }
 endShape();


 //draw object
 fill(0,100,0);
 ellipse(x,y,40,20);

}
Re: Curvy tail with grass leaf shape?
Reply #4 - Jul 27th, 2007, 3:00pm
 
Wow, that's what i want. Cheesy
Thank you for providing the code, lenny
Page Index Toggle Pages: 1