Help understanding iterators, for a simple visual effect

merges's picture

Hi there! I'm completely new to Quartz Composer and not much of a programmer. However, I am more familiar with object oriented programming than this more strictly "loop-based" processing.

Here's what I'd like, in plain language: A bunch of tall, thin rectangles. Each of these rectangles can be addressed individually: So I can tell one of them to change color, for instance. Ideally I could hook up some kind of iterative loop that over time passes a message to each rectangle (not all at once), like so—rectangle 1, change to red now; rectangle 2, change to red now; etc.

My intuition would be to create a prototype/class of rectangle and then create instances of them, and create separate objects to do "animation" control etc. QC seems rather different. I've done some tutorials and have a sense of how it works, but not a solid sense nor do I have an intuition yet.


So, my first goal is to have a sequence of say 8 rectangles. I want them to "light up" from left to right. Well, actually, I want each one to fade from alpha 0 to alpha 1 and back to alpha 0, in sequence. Not all at once.

http://www.merges.net/hosted/iterationOpacityStrip.qtz

The best I could do as a start, is linked above. They fade in one at a time, but don't fade out one at a time. I'm stumped on how to do this without getting extra complicated with nested iterators (and I'm not sure how I'd work with those.) This is a case where some expert help would really be useful!

Thanks in advance for taking a look, if you can. I'm excited to see what QC can do! :)

jersmi's picture
Re: Help understanding iterators, for a simple visual effect

You're really close. Here's one using the Timeline patch (with Patch Time).

PreviewAttachmentSize
iterationOpacityStrip_timeline.qtz5.38 KB

franz's picture
Re: Help understanding iterators, for a simple visual effect

change your LFO's "sawtooth up" to "Sin", and they will animate back to 0 opacity. ?

gtoledo3's picture
Re: Help understanding iterators, for a simple visual effect

Yeah, I'm w/ franz. Use an lfo sin or cos wave to with the timebase hooked to the current position of the iterator variables patch. Hook the result to something that controls alpha, like the rgb color patch. Then maybe use patch time to change the phase of the lfo.

If you're familiar with oop, then you should be super happy, because you can just program whatever you're doing in a plugin if you want. Checkout the adc notes on programming a consumer plugin as a starting point.

merges's picture
Re: Help understanding iterators, for a simple visual effect

This is really helpful and exactly what I was going for, thanks for sharing!

merges's picture
Re: Help understanding iterators, for a simple visual effect

Gtoledo: I don't think I understand what you were suggesting. When I hooked up the LFO/sin with timebase hooked to current position of iterator variables, the series of bars no longer animated. They just "froze" in different states of opacity.

How do I "use" patch time to change the phase of the LFO?

The concepts of patch time/iterator time etc. are not really well explained anywhere, are they? I've found Apple's documentation good for getting a quick composition out but there's almost no conceptual descriptions of patches anywhere. :-/

Thanks for all your help!

usefuldesign.au's picture
Re: Help understanding iterators, for a simple visual effect

(Generalising) Normally patches execute the same way wherever they are in your composition. Inside iterator macros they behave as many instantiated versions of themselves. By using the Iterator Variables Patch you can create logic that will vary the inputs to you rectangle rendering code. A trick in QC to effect the execution of time dependant patches like LFO is right-click on the patch and change it to External Patch-Time. You can then enter patch-time manually instead of it referring to the compositions runtime. Using a Patch Time Patch or a System Time Patch with a Maths patch and Iterator Variables Patch you can offset the phase of the LFO by offsetting its Patchtime input.

ie. pT(for LFO instance i) = CompositionPatchTime + Iterator_Index * 2.0s delay

will mean each instance of the LFO is operating 2.0s after the next instance.