#!/usr/bin/env lua5.1
require[[fp]]
require[[fptheme]]
require[[fpwidgets]]
require[[fpmedia]]
local images = {}
local filenames = { "sea-256x256.avi", "wavy-256x256.avi", "media-256x256.avi",
"bike-256x256.avi", "leaves-256x256.avi", "ribbon-256x256.avi" }
-- The initial settings for cube orientation
local tlt = 25
local dtlt = 1
local angl = 40
local dangl = 1
bg = fp.image{ style = "background", focus = true }
-- Key-handler (arrow keys) callback to control rotation
bg.cb.key_down.down = function(key)
if not cube then return end
if key.keyname == "Left" then
angl = angl-dangl
elseif key.keyname == "Right" then
angl = angl+dangl
elseif key.keyname == "Up" then
tlt = tlt+dtlt
elseif key.keyname == "Down" then
tlt = tlt-dtlt
end
cube:tilt_set(tlt)
cube:angle_set(angl)
return true
end
-- Load the videos from disk. This could just as easily be from a database
-- or over the network.
local vid = {}
for i = 1, #filenames do
vid[i] = fp.media{ file = "data/vds/"..filenames[i],
x = 100*i, y = 0, w = 32, h = 32,
state = "play" }
end
-- The cube understand images, so we pull an image out of the video to hand
-- to the cube.
-- We need to delay the passing of images to the cube until the video is ready.
-- A short delay, quicker than one can see, is usually enough for this.
fp.timer(0.02, function()
for i = 1, #filenames do
if vid[i] then images[i] = vid[i]:image_get() end
vid[i]:layer_set(-1000)
end
-- Load the cube. We delay the cube loading until after we have
-- obtained the images, above.
fp.timer(0.03, function()
cube = fp.cube{ x = 100, y = 100, w = 300, h = 300,
focus = false,
tilt = tlt, angle = angl }
for i = 1, #filenames do
cube:add(images[i])
end
return false
end)
return false
end)
fp.begin()