> Hi all.
> 
> I have a few questions, and thought I'd compile them to a list rather
> then spamming the dev list loads.  If I get an answer others may have
> use for, I can post that as a separate entry later.

No biggy -- I know how you feel.

> 
> OK, let's go.
> 
> 1 >  Let's say I have a sprite moving around using two random nodes,
> one for X and one for Y, possibly also one for Z but I doubt it.  I
> would like to orient the sprite to the direction it travels.  In other
> words, can I have something with a 'front' move 'forwards'?
I haven't played with the Leopard version yet -- so there might be something
to automate this. I've accomplished the same thing in Flash with
actionscript -- so you can do all this in Trig. In this case, I would use
your slope formula, but sample it over time, and take the average slope to
"ease it" towards a direction (at any point in time, you can get a
drastically different slope). If you know the point where the image is
heading, then just put that X and Y as a destination. An interpolator and
LFO should work. Here is an Asteroids game that does some of what you are
looking for, a snippet of JavaScript code here is feeding in the coordinates
of the Player's ship; (
http://www.quartzcompositions.com/phpBB2/upload/details.php?file=279)
" 

    Object.generateAsteroids = function(total, speed, xSafe, ySafe) {
        for(var i=0; i< total; i++) {
            var offset = Math.floor(Math.random()*64)
            var rot = Math.random()
            var rotAroundPlayer = Math.random()
            var distFromPlayer = Math.random() * 1.0 + 0.25
            var x = Math.sin(rotAroundPlayer * Object.PI2) * distFromPlayer
+ xSafe
            var y = Math.cos(rotAroundPlayer * Object.PI2) * distFromPlayer
+ ySafe
            var xv = ((Math.sin(rot * Object.PI2)) / 800) * speed
            var yv = ((Math.cos(rot * Object.PI2)) / 800) * speed
            if (Math.abs(xv)<0.001) { // prevent 100% horizontal
                xv = 0.001 * (Math.abs(Math.random())*2-1)
            }
            if (Math.abs(yv)<0.001) { // prevent 100% vertical
                yv = 0.001 * (Math.abs(Math.random())*2-1)
            }
            Object.objectList.push({"x":x, "y":y, "xv":xv, "yv":yv,
"rot":rot*360, "kind":0, "width":Object.KIND_0_WIDTH, "offset":offset})
        }
    }
"
Note, that you have to "test for ZERO" on the axis. Where X or Y = 0, you
can get your orientation messed up -- that's this line;
"  if (Math.abs(xv)<0.001)  "
That will save you a few hours in bugs if you ever discover this on your own
by trial and error (which I did many years ago -- oh, youth). This isn't
orientating towards the target -- but it contains most of the math you will
need.

This would be a lot faster using the equivalent patches in Quartz.
In Leopard -- I would take a look at that "Ease" patch, which will take the
values you have now, and give a transition value to your destination so it
will gradually orient.

Here is a JavaScript if you are looking to sample values over time;
"
var signal = inputs[0] * 0.5;
var rate = inputs[1];
var avg = signal;
if (inputs[2]>0.01)
    avg = outputs[0];
avg = (signal * rate) + (avg * (1 - rate));
outputs[0] = avg;
"
Or smooth the values;
"
/*
Adds the current iterate weighted by factor to the old value;
input 0 is the tested value
input 1 is the smoothing factor
*/
if ((outputs[0]==undefined) || (outputs[0]==Number.NaN)) {
    outputs[0]=0;
}
if ((inputs[0]!=undefined) && (inputs[0]!=Number.NaN)) {
  outputs[0]=(inputs[0]+outputs[0]*inputs[1])/(inputs[1]+1);
}
"
>> You can also store variables in the JavaScript patch -- wikipedia covers this
so I won't get into it here.

In general, if you want some math based animation that you haven't found in
a Quartz Composition, I'd recommend taking a look at some ActionScript code
-- there is a lot of it out there. JavaScript will work as well, because of
the JavaScript patch -- but ActionScript is perhaps better, because it gets
people thinking more in terms of objects -- breaking up the complexity
(e.g., Patches and Macros). JavaScript is going to have a performance
penalty, and get you thinking in terms of; "if I already have this array of
values here, maybe I should go ahead and calculate this." Take advantage of
the patches whenever possible. At first it seems kind of silly, but I think
conceptually, it allows people to perform more complicated tasks than they
thought they could.

> 
> 2 >  Creating trails that fade.  Is this possible?  I thought it may
> be if I used the Replicate in Time patch, but can't seem to get it
> working.  Imagine a sprite moving around, I'd like to be able to set a
> length and have a tail emit to that length.

I haven't done this yet, but Replicate or Iterator should do it (I'd go for
Replicator on this one). Just use the "Iterator Variables" patch, I would
imagine some pseudocode like the following;
"
Alpha = 1 - ( Current Index / (Iterations-1) )
"
So the first index item is 0, therefore your alpha will be 1. Testing the
code with 10 iterations (or Replications);
Alpha [first object] = 1 - (0 / (10-1) ) = 1;
Alpha [fifth object] = 1 - (5 / (10-1) ) = .44444;
Alpha [last object]= 1 - (9 / (10-1) ) = 0;

Of course, you don't need to have an invisible object, so just do 9
replications and don't subtract 1 from the total iterations. I believe that
the last iteration is "above" the previous -- so keep that in mind.

NOTE: The array index starts at ZERO, so the final item in the array would
be 9, for instance, if you set your total number of iterations at 10. Just
don't try and do 1 iteration with this.

 
> 3 >  Enabling with Audio.  I'd like to have sprites turn on (Enable)
> when a certain input level on the audio input node is achieved.  I
> can't figure this one out, I've tried everything I can think of with
> ranges, multiplexer etc.  No joy.
Use the "Audio Input" patch to determine your sound source.

There are a lot of examples of iTunes screensavers -- just search for
"iVisualize" or "BeComposed" -- they do a lot of audio reactive animations.
The thing to realize is that Quartz doesn't Hold or load the sound -- it
just reacts to it "passing through." The new Leopard version of this has
improved access to sound in Quicktime.

Just play around with any very basic audio reactive visualizer.
 
> 4 >  Gravity, or attraction.  Is this in any way possible, even as  a
> fake?  Let's say I have some sprites, I want them to slowly move
> together over time.  Or have some sprites move toward something else,
> I'm not fussed what.  Basically, can one thing attract another?
Go look for some Math examples of this in Flash. I know that a lot of the
math-based VJ animation tools out there may do this as well, but
Actionscript will be more approachable and translatable to Quartz.
The Particle Systems, however, do allow you to add attraction and gravity.
There might be something more for this in the Leopard version -- I don't
know. If they don't have it built in, or you are using particles, then you
are going to have to build an array of values, and determine distance from a
center point as you iterate through the array over time (sounds like a
Javascript patch here). Do the calculation outside of any Replicate or
Iterator patch and feed the values to each object based upon their location
in that array (iterator Index). Gravity is a bit easier on a group of
objects, because you are always subtracting from the vertical, until you
reach a maximum speed or the ground.

Not having done this, I'd expect instead of doing slope calculations, you
would just want to look at some math for velocity, and vectors (and of
course a vector can also be a rotation -- big HINT that you can just to a
vertical axis and "rotate" your group away from center -- but your
calculation is merely Y velocity over time) -- that will make your math
simpler than a lot of slope over time calculations.

Or, you could just use the Interpolator and some sort of 3D container like
"Trackball patch" --- I haven't tested the overhead on all of these so
you'll want to experiment. Just tackling the "attraction" for various
objects (since gravity is so easy), I'd put all my objects in a Trackball.
The "collision" is 0,0 value. The Interpolator only changes the Y value in
each sprite -- inside the trackball. Some other value -- perhaps random (I'd
randomize duration for each interpolated value to make it less "perfect"),
changes the orientation of each 3D group. You could use this to achieve a
"flocking" look. Randomize the final destination values so that they are
slightly apart at beginning and end for a swarm. Essentially, you have
traded the extra math to figure out each vector, by having multiple objects
merely share the same "home" location but have different orientations.

I'm sure that's a lot easier than iterating over an array of slope/position
coordinates. You can even move the main 3D group in space, and not have to
worry about your math. All objects within are functioning on their own local
coordinate system. Piece of cake, no?
 
> 5 > Hold and move.   Imagine a sprite, it moves to a random point
> slowly, then pauses for 2-3 seconds, then moves to another random
> point, this continues. I can get it all working, but can't get the
> pause/hold part working.
Use a trigger that gets set when the movement stops -- the trigger changes
the input switch on a Multiplexer that just has two "random" value feeds.
I've always used the multiplexer to "reset" and to hold variables (they've
fixed this issue in Leopard with new patches). The Random value that comes
out is Added to a snapshot from the trigger of the current patch time. The
"Pause and Hold" patch (I'm getting lazy here), will look for a time some
random bit in the future to start moving again. And you could also use an
"ease" patch here in Leopard to make the motion really slow down and not
fully stop.

The custom interpolation curve (Command + 3) on the interpolator can give
you a pause -- but that is REALLY hard to control, and won't change each
time.

You can use the Counter Patch with a Math (Mod 2), so that you always switch
from 0 to 1 on the multiplexer -- OK, maybe Stopwatch can do that all on
it's own, the Coffee isn't strong enough this morning -- this one should be
pretty easy to do once you figure a "pause" is just the current time + a
random amount of time in the future. If you want to make this really nice,
you can create two macros with a "Patch time" patch and a random patch in
each -- just create a max and min setting for your values -- you now have a
random timer macro that starts a clock from zero each time it is called.
 
> Many thanks for looking through this, and thanks on advance for any/
> all help.
> 
> Regards.
> 
> Andrew.
Good luck.

My apologies to everyone else if this is too verbose and "basic" -- I just
know when you are starting out it helps to have a little bit of obvious
thrown in. There are people here writing Kernel transforms and some people
who have to sweat a bouncing particle. Feel free to improve on my advice --
especially with the "attraction" trick.

-- Mark J

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartzcomposer-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to