#!/usr/bin/env lua5.1 require[[fp]] require[[fptheme]] require[[fpeffects]] require[[fpwidgets]] bg = fp.image{ style = "background", focus = true } filenames = { "greenapple.jpg", "candy.jpg", "shell.jpg", "sunny.jpg", "splash1.jpg", "cactus.jpg" } -- Six sides to the cube, six images assert(#filenames == 6) -- We display the images. The images must be first displayed in order for the -- 3D textures to be created. images = {} for i = 1, #filenames do images[i] = fp.image{ file = "data/"..filenames[i], x = 100*(i-1), y = 0, w = 100, h = 100 } end -- In this cube example we rotate with finer degrees of control along -- all axes. -- The initial settings for cube orientation local tlt = 25 local dtlt = 1 local angl = 40 local dangl = 1 -- 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 -- We need to delay the creation of the cube until the images are rendered timer = fp.timer(0.1, function() -- The tilt parameter specifies vertical title -- The angle parameter specifies the offset of the -- faces from 0 degress. cube = fp.cube{ x = 150, y = 80, w = 300, h = 300, focus = false, tilt = tlt, angle = angl } -- Add each image to the cube and hide the original -- image once rendered. for i = 1, #filenames do cube:add(images[i]) images[i]:layer_set(-999) end return false end) -- By default the cube intercepts the left and right button down events -- and rotates so there is no need to add event callbacks for anything else -- It stops spinning at a multiple of the given angle. fp.begin()