Demo effects...

psonice's picture

Updated - I've added v2. It now features the javascript timer cwright kindly posted, so it's now MUCH smoother, plus a better image and a bit of colour shifting.

I'll probably post a few of these, so they can all go in here :)

  • note: if it runs slowly or glitches, it's down to the way the effect works. Make your window smaller and reload - it should look nice and smooth when it's right!

First one, a really oldschool effect popular back in the amiga and atari days when computers were 16 bit: infinite bobs. I tried to do this when I first started with QC, and failed miserably. Now I've figured it out :) So, what it is and how it works...

Back in the olden days, you could only move a limited number of sprites around the screen at once (and actually the same applies now, it's just that modern hardware can probably push more than you could actually see at once!). With this effect, you can put 'infinite' sprites onto the screen, all moving at once, even with oldschool hardware.

It works by having multiple frame buffers (I've used 5 here), switching between them each frame, and rendering the sprite to each buffer in turn as it moves. The buffers are never cleared, so when you get back to the first buffer, you get 2 sprites shown on screen. Because the 5 buffers capture a short sequence of animation, you get the illusion that more and more sprites are appearing on the screen, where there's really just one.

To make this work in QC, I've used 5 accumulators to build up the images, and a multiplexer and demultiplexer to switch between them. The movement is just a moving sprite in a render in image patch.

Because it's frame-rate dependent, it'll look ugly if anything slows it down. Also, it's only running at 30fps because the counter patch seems to stop working at 60fps, and it does strange things as it approaches it :( Anyone know of a better way of switching frame buffer, preferably per frame?

PreviewAttachmentSize
infinitebobs.qtz13.34 KB
infinitebobs2.qtz22.09 KB
bobs2.jpg
bobs2.jpg56.62 KB

tobyspark's picture
interesting... and somehow

interesting... and somehow just looking at it fills my head with 8bit music =]

cwright's picture
switch per frame

I'm surprised there isn't a frame counter (that I could find, at least). However, it's simple to make one in javascript using some mild trickery.

framecounter demo

Here's the code in copy/paste-friendly form:

/*
We take advantage of the fact that js only
executes when the input changes.  As long as the input's different
each frame, it'll be a faithful frame counter for us.  We could also 
add some frame count reset inputs too if we wanted to be fancy :)
*/
var frame = undefined;

function (__number outputNumber) main (__number ChangeMe)
{
   if(frame == undefined)
   {
      frame = new Object;
      frame = 0;
   }
   frame++;
   var result = new Object();
   result.outputNumber = frame;
   return result;
}

(we attach patchtime because it's guaranteed to be different each frame, so it'll keep the js counter running as expected)

[edit: I clearly don't know javascript either.. perhaps the "frame = new Object" is unnecessary? no idea.]

PreviewAttachmentSize
FrameCounter.jpg
FrameCounter.jpg102.24 KB

yanomano's picture
Good code...

It's a good idea christopher. I was waiting for something like this, because as we can't evaluate the real FPS of a comp it is impossible to solve timecode or frame count with math...

to be really efficient your javascript should have 2 other functions : - One for read the frame in reverse in local time (rewind) : frame --; - One to read the movie position in frame from a movie loader (in this case the javascript must have a second input to read the movie duration and reset the counter each time the loop end...this is the difficult part :)

yanomano.

psonice's picture
Excellent!

I was originally thinking if there was a way to make it without additional code, but this makes a lot more sense (and it's actually possible, which helps ;)

Between this and Patch Time, it's possible to do both frame-rate dependent effects and correct synching.

The only other thing time related that would be handy is the FPS Display patch - it should be possible to pass the FPS as an output, not just display it. It'd be pretty trivial to do that with your js, but at some point I think I'll modify the original FPS patch instead as I need something like that for my demo project. I plan to have a performance test at the start, and then adjust the complexity of the effects to get a decent framerate.

cwright's picture
dynamic complexity

If you're going to go with the dynamic complexity route, I'm going to make a request that you do it at regular intervals during the demo, not just at startup. My machine is usually swamped with protein-folding work in the background, and I only disable it when I notice performance problems with appps I'm using (since Leopard doesn't honour nice as it should... more grumbles at Apple). Having it increase in prettiness when the CPU load drops, without having to restart the app, would be sweet! :)

[By the way: forgot to say how cool the demo is. I forgot about being clever now that we've got so much cpu power these days. Good to get back to our roots :) Thanks for the refresher :)]

psonice's picture
A good idea, but...

Not really possible. The way the effect works is that it's totally free to generate objects and grow/manipulate them, but only as long as there is 'energy' available in the system. The energy limits the total complexity of the scene, including the number of objects and the complexity of each one, and the total energy parameter is passed to the algorythm at startup. Changing it later would mean breaking it. :(

Oh, and thanks :) I'll try to update it at lunch time with the js timing and a slightly prettier bob. Then back to looking at the CV stuff.

psonice's picture
Added in

I've added this in, and updated the composition. It's now much improved, and I'll leave it there :)

franz's picture
framed playback

To playback frame by frame, normally you don't need any javascript patch: if your movie is 25 fps (in Pal, normally, or did they switch to NTSC in Bordeaux ?), then divide your desired movie location by 25: if you want to go to frame 1000: 1000/25 = 40. So enter 40 seconds in the movie time input. Since calculations are floating point, it stays precise. At 327 frames timecode would be a 13.08 seconds.... looks weird, but it is the same numbers. You just have to know your original framerate and externalise timecode.

The auto reset loop was tricky with QC 2.0, but now with 3.0, colesd looped are allowed within the graph, so you can just connect a stop watch to a conditionnal patch, then connect back the output of the conditionnal to the reset intput of the stopwatch (am i clear ??)

I made the whole Etienne de Crecy's show under QC with timecoded functions and triggers, and it was accurate without needing any scripting, just math.

psonice's picture
Handy to know

Handy to know, but the javascript was necessary here because there is no movie in the composition - everything is generated realtime, and the framerate varies if the system can't keep up. That causes major glitches in any effects that rely on the framerate, which is also the case in that composition.

Another thing that's handy to know is that you can use the movie time output to synchronise things to an audio soundtrack:

  • Load an mp3 or whatever into the movie loader patch
  • Connect a billboard or whatever to the image out so it 'renders' (even though it won't show anything as there is no video)
  • On the movie loader patch settings, enable Asynchronous mode

You can then use an audio file in your composition and keep accurate timing.

psonice's picture
Signal patch

Also, the signal patch is your biggest friend here - it generates a signal after x seconds, or every x seconds. Makes timing transitions etc. very easy. It's a private patch btw.

cwright's picture
Minor nit pick

Since calculations are floating point, it stays precise

This isn't accurate: Integer math is precise on computers(provided you don't over/underflow), but floating point math suffers from rounding error. It's usually not a big amount (i.e., for frame/time calculation it probably won't matter unless you deal with movies that are trillions of frames long or more), but doing math in FP is not, in fact, precise.

franz's picture
"the framerate varies if the

"the framerate varies if the system can't keep up" : use a system time to generate the timecode, not a patch time !

psonice's picture
doesn't work...

If you do that, you find that the source images (which are generated by QC) suffer frame rate slow downs, while the main effect continues to run without receiving new data. You then get glitches aplenty.

The rendering of the main effect has to be tied to the generation of the input images - that's the whole point of a frame-rate dependent effect. The javascript produces a timer that increments when the source input updates, which means it normally runs at 60fps, but if anything slows the input down, the whole playback slows down but the effect isn't disrupted.

Compare the two compositions at the top (infinitebobs and infinitebobs2) - the first one (which uses a normal timer) glitches horribly if you mess around with something that causes it to slow down, the second one (with the javascript) stays pretty smooth.

franz's picture
or does it ?

I was referring to yanomano's post: "One to read the movie position in frame ".

It does definetly work when dealing with QT movies. It doesn't work when generating images from within QC.

psonice's picture
Ah, totally lost the thread there...

So apologies for that.

Re-reading yanomano's post got me thinking though - he mentions using the javascript to count frames back. Is there a way to actually jump to a certain frame or time in a movie? Because you could do some very cool stuff with time-based effects.

cwright's picture
timebase

You can jump to arbitrary times by making the movie loader's timebase external (right click the patch) -- then you have complete control over playback, including fastforward, rewind, and pause. And other fun stuff.

yanomano's picture
system time, yes !..:)

i had totally forgot(en) this little blue patch...! Thanks frantz

yanomano.

yanomano's picture
Time To timecode uploaded

I've done this little simple macro patch. You can plug "QC time" into it (Movie duration, movie position, Patchtime, System time.....) and it outputs a regular time code in the 0:00:00:00 format. You can choose the Frame rate from a menu with : 23,98 FPS 25 FPS 29,97 FPS

Don't know if it help ...

yanomano.

PreviewAttachmentSize
Time to timecode.qtz7.03 KB