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 › points following a moving curve
Page Index Toggle Pages: 1
points following a moving curve (Read 813 times)
points following a moving curve
Jan 22nd, 2006, 3:13am
 
Hi,

I have been looking at points on a curve - I want to use these points as info-points, so
1) How do I make the points follow a moving curve, and
2) How do I get the coordinates of each point written into a list?

Here's the code:

void setup(){
 size(300, 300);
 stroke(200, 100, 200);
 }




void draw(){
background(0);

float xP = mouseX;
float yP = mouseY;

 curve(5, 26, xP, yP, 73, 24, 73, 61);
 //curve(5, 26, 73, 24, 73, 61, 15, 65);
 ellipseMode(CENTER);
 int steps = 6;
 for (int i = 0; i <= steps; i++) {
   float t = i / float(steps);
   float x = curvePoint(5, 5, 73, 73, t);
   float y = curvePoint(26, 26, 24, 61, t);
   ellipse(x, y, 5, 5);
   
 }

}
Re: points following a moving curve
Reply #1 - Jan 22nd, 2006, 7:32am
 
I'm going to try and answer your question as simply as possible, and still give you room to explore.

Your first question:
 How do I make the points follow a moving curve?

Let's simplify your problem. So long as you can get ONE point (or ellipse, or whatever else) to move along a curve, then you can move points (plural) to follow a curve.

You also wanted a "moving curve". I don't know what that is exactly, but I'll ignore it for now and focus on a "curve".

First, you need to define a curve. Be it, from Bezier or Curve. Check the references on what values they'd like to take:

http://processing.org/reference/curve_.html

Something like that will do. You'll notice that a catmull-rom curve like that takes 8 variables (4 points on 2D space).

Now, that command is only to draw the curve. The curve is simply an abstract set of data-points. However, Processing readily gives you a method to find any point on a curve, so this is extremely useful:

http://processing.org/reference/curvePoint_.html

Notice its usage: calling it twice to recieve the x and y, by supplying it with a variable 't'. 't' defines how far along the curve the function will return a point at. Therefore, if you give it a value of '0', it will give you the x and y position of the beginning of the curve. A t of '1' will return the positions of the end. And a '.5' will return the middle. We cool so far?

So, to "animate" something along the curve, you "animate" this 't' number.

Something like:

Code:

progress += .1;
px = curvePoint(ax,bx,cx,dx,progress);
py = curvePoint(ay,by,cy,dy,progress);

//px and py can now be used for drawing.


Looking at your code, you seem to understand this. Yet, you are cycling through "t" in one for-loop. Remember: your screen does not refresh until the END of draw(). Thus, you have to increment your "t" only once every frame.

That's about it, for your first question.




For your second question:
 How do I get the coordinates of each point written into a list?

I'm not sure I understand it. Can you please be more specific? Do you want to know how to store the animated points into an array? I don't quite follow.


Anyways, good luck.
Re: points following a moving curve
Reply #2 - Jan 22nd, 2006, 7:55am
 
Wow, what a pedagogically sound approach in offering assistance. It's so much easier to go ahead and simply solve someone's problem, but to, in your own words: "still give...room to explore"-that's real TEACH'N!! I've been teaching for 10 years and still struggle with this. Thanks for the inspiration!
Re: points following a moving curve
Reply #3 - Jan 22nd, 2006, 10:31am
 
Hah, thanks Irag. Unfortunately what usually happens is that I type a prolonged monologue about how to procedurally think about the problem, someone else swoops in with working source code...

I simply find the thought process more useful than source code itself. But, you are welcome!
Page Index Toggle Pages: 1