Page Turn Effects and Peel & Roll Effects

Download the source code.
Play the video
Back








10









20









30









40









50









60









70









80

#!/usr/bin/env lua5.1

require[[fp]]
require[[fptheme]]
require[[fpwidgets]]

PIC_W = 200
PIC_H = PIC_W
PIC_X = 100
PIC_Y = 100

bg = fp.image{ style = "background" }

-- A predefined set of filenames.  This could come from anywhere really,
-- such as a database or the network.
-- These images are all square.  The transform effect only works on square
-- images for the time being.
filenames = {
   "cactus.jpg", "candy.jpg", "cloudy.jpg", "egg.jpg", "grass.jpg", "greenapple.jpg", "illy.jpg", 
   "milk-orange.jpg", "pumpkins.jpg", "robot.jpg", "sandy.jpg", "shell.jpg", "spices.jpg", 
   "splash1.jpg", "splash2.jpg", "stripey.jpg", "sunny.jpg", "yellowglasses.jpg" 
}

-- Declare the images table.
images = {}

-- Lua tables start at 1.  We go through each element in the filenames
-- table, load the file and put it into an images table.
-- Note there is no error checking in this simple example.
for i = 1, #filenames do
   images[i] = fp.image{ file = "data/"..filenames[i],
			 x = PIC_X, y = PIC_Y, w = PIC_W, h = PIC_H }
end

-- The layering of images is in reverse order because that's the way we
-- loaded them.  Images loaded later get put on a higher layer.  We want
-- to keep track of the bottom image in the stack as we will put the
-- image at the bottom once the transformation is complete.
current = #filenames
bottom  = 1

-- Set up a timer to run every 2 seconds.  This runs the function to
-- do the 3D effect on the image and then move it to the bottom
-- of the stack.
t = fp.timer (2, 
	      function()
		 -- Get the current image
		 -- Get a random direction.  The roll direction can be
		 -- 1 of 4, left, right, up and down.  The peel direction
		 -- can be 1 of 2, left and right.
		 local img = images[current]
		 local dir = math.random(1, 4)

		 -- Randomly select which of the 3D effects to use.
		 if math.random(1, 2) == 1 then
		    -- The peel is a separate object that needs to be
		    -- created.  It takes a copy of the oringinal image.
		    peel = fp.peel{ image = img, x = PIC_X, y = PIC_Y, w = PIC_W, h = PIC_H }
		    -- This call executes the peel in the given direction.  Directions for
		    -- peels are diagonally left or right.
		    peel:peel((dir % 2) + 1)
		 else
		    -- The roll is a separate object that needs to be
		    -- created.  It takes a copy of the oringinal image.
		    roll = fp.roll{ image = img, x = PIC_X, y = PIC_Y, w = PIC_W, h = PIC_H }
		    -- This call executes the roll in the given direction.
		    -- Directions for rolls are left, right, up and down.
		    roll:roll(dir)
		 end
		 -- Move the original object to the bottom of the stack
		 -- once started
		 img:stack_below(images[bottom])
		 bottom = current
		 current = current - 1
		 if current == 0 then
		    current = #filenames
		 end
		 return true
	      end)

-- Start the main loop.
fp.begin()