Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Example program for the use of Lumiere
- -- Matti Vapa, 2014
- -- load the Lumiere as a module
- os.load("lumiere")
- -- URLs to some static images
- local url1 = "http://web.inter.net/funnypic.png"
- local url2 = "http://google.wikipedia.com/catnicorn.jpg"
- -- URL to a gif animation
- local url3 = "http://www.pixelsaresupercool.com/snazzyanimation.gif"
- -- set the screen dimensions
- local width = 16
- local height = 16
- -- this function initializes the screen, the prototype is
- -- initScreen(width, height, side)
- -- side is where the modem is located on the computer
- -- the function returns a screen object
- local screen = lumiere.initScreen(width,height,"back")
- -- use Lumiere to download the images and animation
- -- the functions take as an argument an URL and the
- -- length of the largest dimension you want
- -- images will be up- or downscaled to fit this
- -- here we use the longest side of the screen as the size
- local funny = lumiere.getImage(url1, math.max(screen.width, screen.height))
- local cat = lumiere.getImage(url2, math.max(screen.width, screen.height))
- local anim = lumiere.getAnimation(url3, math.max(screen.width, screen.height))
- -- check if some of the downloads failed
- if (not funny) or (not cat) or (not anim) then
- print("Getting the images failed :(")
- return
- end
- -- Lumiere can create images of one solid color, give as 0xRRGGBB
- local red = lumiere.getColor(screen.width, screen.height, "0xFF0000")
- local blue = lumiere.getColor(screen.width, screen.height, "0x0000FF")
- -- set the screen first to white
- -- note the use of : here
- screen:setColor("0xFFFFFF")
- sleep(1)
- -- in Lumiere there is a fade effect which fades between two images
- -- the prototype is
- -- fade(screen, start, end, steps, speed)
- -- you have to pass the function a screen object to draw on
- -- start and end are the initial and final states of the animation
- -- steps is the number of steps in the fade sequence
- -- the function will sleep 1/speed seconds between each frame
- lumiere.fade(screen, red, blue, 20, 5)
- sleep(1)
- -- use showImage to display an image
- -- prototype is
- -- showImage(image,x,y)
- -- x and y are the screen coordinates of the image
- -- with 1,1 being the upper left corner
- -- x and y can be out of the screen bounds
- screen:showImage(funny,1,1)
- sleep(1)
- -- with draw coordinates we can scroll the screen
- -- this will scroll the screen down out of view
- -- this might be flickery
- for y = 1, screen.height do
- -- each loop first set the screen black
- screen:setColor("0x000000")
- -- and display the image one row lower than before
- screen:showImage(funny,1,y)
- sleep(0.3)
- end
- -- clear the screen with black color
- screen:setColor("0x000000")
- sleep(1)
- -- fade from black to the second image
- -- note that the faded images need to be of the same size
- fade(screen, lumiere.getColor(screen.width,screen.height,"0x000000"), cat, 10, 2)
- sleep(1)
- -- display the animation
- -- gif support is very very very primitive
- -- and some gifs don't work at all (blame the Python Image Library)
- -- the last parameter is speed, with 1/speed seconds of sleep between
- -- frames
- screen:showAnimation(anim,1,1,3)
- sleep(1)
- -- set screen to default yellow color of the illuminators
- screen:setColor("0xFFFF00")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement