Sg2.9
advice on approach
Recent RSS
advice on approach
Date:  18. July 2006, 04:45

I think, perhaps, that I'm not getting something, conceptually, so I'm looking for some advice. This is regarding an interactive tool.

let's say that the tool starts at x0, y0 and is dragged about, ending at xn, yn.

In between, we want the width of the shape created to vary by the speed the tool is moving. Calculating that speed is easy - we can look at the last point it was at and the current point that it is at and do the distance. Here is where I have questions, though... and I really feel like I should be able to answer these, but I'm looking for help.

a. I can easily make a path along all the points that the mouse moves by just adding segments, but what I'm describing would have two paths diverging from x0, y0 and closing at xn, yn (to make one complete path). I tried creating parallel segments for this, but it really didn't seem to work. Does anybody have any scripts that show an example of how to do this? I think that I'm not getting something with how the AI Art works.

b. This is more conceptual - everything I create ends up looking like somewhat of a ribbon -- that makes sense, since if I am offsetting my x and y values for the second path, and then cut back at an angle, they should appear much closer. But I also tried this with calculations through Point.getAngle and Point.rotate, and the results are the same, so I'm stumped. What I'm looking for, in the end, would be like a variable thickness outline stroke on a path... anyone have any advice?

Ok, starting off with two "help me" questions -- I'll do my best to return the favor to future stumped scripters when it comes to areas that I can help with.

Thanks,

Charles

Re: advice on approach
Date:  18. July 2006, 12:57

I'm not quite sure that I understood your questions, but I'll try to answer.

Let's say we have a loop.
Each iteration, you know xmouse and ymouse and you store it in some variables.

(I'm not very familiar with scriptographer syntax, so i'll do it in "pseudocode". Plus, I haven't tested it, it must be full of errors ^^)

// Init mouse old position
oldPx = mouse.x;
oldPy = mouse.y;

// Each iteration, do
onMouseMove {
// Store current mouse position
Px = mouse.x;
Py = mouse.y;

// Calcutate difference between old mouse position and current mouse position
Dx = Px-oldPx;
Dy = Py-oldPy;

// Calculate hypotenuse = distance between the 2 positions (Pythagore)
Dmouse = Math.sqrt(Math.pow(Dx,2)+Math.pow(Dy,2))

// Calculate angle
Theta = Math.atan2(Dx,Dy);

// Store mouse position
oldPx = Px;
oldPy = Py;
}

I'll finish my answet later, got work to do =)

Re: advice on approach
Date:  18. July 2006, 16:15

Thanks, Melka. Ok, so your code, with specific Scriptographer references, is something like this... other than verifying what Point.getAngle() returns (It simply says "Number" in the reference), I get all of this:

function onMouseDown(event){
oP = new Point(event.point.x, event.point.y);
}
function onMouseDrag(event){
nP = new Point(event.point.x, event.point.y);
d = nP.getDistance(oP);
theta = nP.getAngle(oP); // is this the same as Math.atan2(dx, dy)?
oP.setLocation(nP.x, nP.y);
}

But I'm still not sure how to create a closed path or how to calculate things so that they don't look like a ribbon.

Re: advice on approach
Date:  19. July 2006, 11:01

Yeah, sorry, I forgot to continue yesterday evening after leaving my work ^^

I attached a small schematic to explain what i'm saying.

Now that you know your angle (theta) and the velocity (d), you just need to add 2 points for your segment.
On the schematic, you'll notice the black stroke between oP and nP : it's the mouse movement. Using this, you simply add 90° to theta, you use d as a basis (maybe you'll need to divide it by a constant) for the red stroke length and you can calculate the coordinates of the point using pythagore.

I'll let you search for it, I don't have time right now.

Hope you understood my approach, certainly not the best but I think this should be working.

Re: advice on approach
Date:  24. July 2006, 15:20

Were my answers useful?

Re: advice on approach
Date:  15. April 2007, 05:03

melka,

yes, if i recall, your answers were very useful -- i completed the project.

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Cross Hatch Raster 15.03.12