More saving

If you’ve used the _.stage.startSaving() and _.stage.stopSaving() functionality recently added you might notice that there’s something missing. These calls save out every frame that’s drawn (either caused by an explicit _.stage.frame() or by a window updating). This can be find for sketches that control their own flow of time on a frame-by-frame basis. But for more complete sketches that use the Field window as a timeline, it’s not quite enough — to turn all of those frames back into a movie, we need to know what the ‘frame-rate’ of that frame sequence is.

The code that’s missing is very straightforward:

_.name = "save_at_24fps"

// in frames per second
var targetFrameRate = 24

// common throughout Field, unless you've decided otherwise
var secondsToPixels = 24

// you could also write start = 0 
// if you always want to start at the '0'
var start = _.time.frame.x

// some feedback
_.label.s = _.stage.startSaving()

var tick = 0
while(_.wait()) {
	_.time.frame.x = tick*secondsToPixels/targetFrameRate 
	_.redraw()
	tick += 1
}

_.stage.stopSaving()

_.label.s = ""

// decoration
_.boxBackground = vec(0.23, 0.5, 0.8, 0.6)

// don't let Field run this with the red line
_.windowSpace = vec(0,0)

There are two numbers in there that you’ll be interested in targetFrameRate = 24 and secondsToPixels = 24. The latter is common throughout Field and its documentation, and it sets the scale between the coordinate system that boxes are in (for things like _.frame.x or _.time.frame.x) and wall-clock time in seconds. targetFrameRate asks for the frame-rate of the resulting jpeg sequence — it’s what you need to specify when you load the image sequence back into an Adobe or Apple product. 24 is enough for cinema, but you could do 12 for a low-frame-rate feel or 240 if you want to play tricks with motion blur in post-production.

The key here is that everything is being saved some constant framerate, and _t() moves regularly because of that. This way, sound will line up with the images that you make.