von dp am 06.Januar 97 um 00:44:54:
zu: Perlen aus dem Strom der Nachrichten im direct_L von Daniel am 22.Dezember 96 um 02:00:59:
Date: Wed, 23 Oct 1996 20:16:40 EDT
From: John Dowdell <71333.42@CompuServe.COM>
Subject: Re: Circular Slider Code...
Richard Schedler writes on Oct 22, "Or even a wavy line? Sorry maths wasn't my
strong point either. Anyone got any ideas?" Gary Martin later adds, "Can an
object be constrained to a line on an angle?"
The following handler will control this type of constrained drag. Note that this
is not a universal solution... will not cover wavy lines which double back on
themselves, and so the thread has diverged from its title a bit... but the
following can handle wavy and angled lines, among other paths.
>> -- Sprite script to constrain drag to a wavy line.
>> -- Field "path points" contains a list of points.
>> -- (Requires field because data may be >256 chars.)
>> -- Assumes that positions are recorded from left to right.
>> -- If path is vertical, record points from top down.
>>
>> on mouseDown
>>
>> -- Change this for your own movie:
>> set thePath to value(field "path points")
>>
>> puppetSprite (the clickOn), TRUE
>> repeat while the stillDown
>> repeat with x in thePath
>> if the mouseH < the locH of x then exit repeat
>> end repeat
>> set the loc of sprite (the clickOn) to x
>> updateStage
>> end repeat
>> end mouseDown
How to get these data points? Easiest is just to tween them out in the Score,
preview and tweak their positions. You can then run the following designtime
utility handler to collect the positions of the selected sprite span and plop
them into a textfield for runtime use:
>> on PathToList
>> -- Find which cells in the Score are selected:
>> set cells to getAt(the scoreSelection, 1)
>> set chan to getAt(cells, 1)
>> set startFrame to getAt(cells, 3)
>> set endFrame to getAt(cells, 4)
>> set theList to []
>>
>> -- Pick up the data:
>> repeat with i = startFrame to endFrame
>> go frame i
>> add theList, the loc of sprite chan
>> end repeat
>> put theList into field "path points"
>> end PathToList
Does this do what you wish...?
Regards,
John Dowdell
Macromedia Tech Support
>It seems to me that if you worked in the bezier code that was posted by
>Darrel Plant at:
>
>http://www.moshplant.com/direct-or/
>
>you could have a constrained slider sprite go just about anywhere you
>wanted it to and at varying speeds as well (depending on the control
>handles and the distance between control points).
If anyone does this, please let me know, I'll be working on my own version,
as well, but due to other deadlines I might easily get sidetracked.
If you want to see an example of Beziers in action, check out the
*unfinished* version of the VirtuOuija board. Tap the planchette with the
cursor, then click anywhere on the board (or type in a letter) and watch it
move!
http://www.moshplant.com/ouija/ouija.html
------
>All this talk of constraining objects to lines reminds me of a problem
I was
>always curious about;
>Can an object be constrained to a line on an angle?
>And if so, How?
Try this, with the "constraint1" and "constraint2" points being the two
ends of your line, at any angle except vertical (where the slope is
infinite):
on mousedown
set constraint1 =3D point(200,200)
set constraint2 =3D point(300,150)
set maxX =3D max(the locH of constraint1, the locH of constraint2)
set msnafu =3D min(the locH of constraint1, the locH of constraint2)
set maxY =3D max(the locV of constraint1, the locV of constraint2)
set minY =3D min(the locV of constraint1, the locV of constraint2)
set m =3D float(the locV of constraint2 - the locV of constraint1) =AC
/ (the locH of constraint2 - the locH of constraint1)
set x1 =3D the locH of constraint2
set y1 =3D the locV of constraint2
=20
repeat while the mouseDown
set x2 =3D the mouseH
set y2 =3D the mouseV
=20
--* TO CONSTRAIN TO AN ANGLED LINE, USE THIS...
set y =3D 0.5 * (m * (x2 - x1) + (y2 + y1))
set x =3D 0.5 * (1/m * (y2 - y1) + (x2 + x1))
set constrainedX =3D integer(min(maxX,max(msnafu, x)))
set constrainedY =3D integer(min(maxY,max(minY, y)))
=20
set the loc of sprite the clickOn =3D point(constrainedX,
constrainedY)
updatestage
end repeat
end
D. Plänitz