Advertisement
hbar

lumiere-example

Mar 15th, 2014
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.20 KB | None | 0 0
  1. -- Example program for the use of Lumiere
  2. -- Matti Vapa, 2014
  3.  
  4.  
  5. -- load the Lumiere as a module
  6. os.load("lumiere")
  7.  
  8. -- URLs to some static images
  9. local url1 = "http://web.inter.net/funnypic.png"
  10. local url2 = "http://google.wikipedia.com/catnicorn.jpg"
  11.  
  12. -- URL to a gif animation
  13. local url3 = "http://www.pixelsaresupercool.com/snazzyanimation.gif"
  14.  
  15. -- set the screen dimensions
  16. local width = 16
  17. local height = 16
  18.  
  19. -- this function initializes the screen, the prototype is
  20. -- initScreen(width, height, side)
  21. -- side is where the modem is located on the computer
  22. -- the function returns a screen object
  23. local screen = lumiere.initScreen(width,height,"back")
  24.  
  25. -- use Lumiere to download the images and animation
  26. -- the functions take as an argument an URL and the
  27. -- length of the largest dimension you want
  28. -- images will be up- or downscaled to fit this
  29. -- here we use the longest side of the screen as the size
  30. local funny = lumiere.getImage(url1, math.max(screen.width, screen.height))
  31. local cat = lumiere.getImage(url2, math.max(screen.width, screen.height))
  32. local anim = lumiere.getAnimation(url3, math.max(screen.width, screen.height))
  33.  
  34. -- check if some of the downloads failed
  35. if (not funny) or (not cat) or (not anim) then
  36.     print("Getting the images failed :(")
  37.     return
  38. end
  39.  
  40. -- Lumiere can create images of one solid color, give as 0xRRGGBB
  41. local red = lumiere.getColor(screen.width, screen.height, "0xFF0000")
  42. local blue = lumiere.getColor(screen.width, screen.height, "0x0000FF")
  43.  
  44. -- set the screen first to white
  45. -- note the use of : here
  46. screen:setColor("0xFFFFFF")
  47. sleep(1)
  48.  
  49. -- in Lumiere there is a fade effect which fades between two images
  50. -- the prototype is
  51. -- fade(screen, start, end, steps, speed)
  52. -- you have to pass the function a screen object to draw on
  53. -- start and end are the initial and final states of the animation
  54. -- steps is the number of steps in the fade sequence
  55. -- the function will sleep 1/speed seconds between each frame
  56. lumiere.fade(screen, red, blue, 20, 5)
  57. sleep(1)
  58.  
  59. -- use showImage to display an image
  60. -- prototype is
  61. -- showImage(image,x,y)
  62. -- x and y are the screen coordinates of the image
  63. -- with 1,1 being the upper left corner
  64. -- x and y can be out of the screen bounds
  65. screen:showImage(funny,1,1)
  66. sleep(1)
  67.  
  68.  
  69. -- with draw coordinates we can scroll the screen
  70. -- this will scroll the screen down out of view
  71. -- this might be flickery
  72. for y = 1, screen.height do
  73.     -- each loop first set the screen black
  74.     screen:setColor("0x000000")
  75.     -- and display the image one row lower than before
  76.     screen:showImage(funny,1,y)
  77.     sleep(0.3)
  78. end
  79. -- clear the screen with black color
  80. screen:setColor("0x000000")
  81. sleep(1)
  82.  
  83. -- fade from black to the second image
  84. -- note that the faded images need to be of the same size
  85. fade(screen, lumiere.getColor(screen.width,screen.height,"0x000000"), cat, 10, 2)
  86. sleep(1)
  87.  
  88. -- display the animation
  89. -- gif support is very very very primitive
  90. -- and some gifs don't work at all (blame the Python Image Library)
  91. -- the last parameter is speed, with 1/speed seconds of sleep between
  92. -- frames
  93. screen:showAnimation(anim,1,1,3)
  94. sleep(1)
  95.  
  96. -- set screen to default yellow color of the illuminators
  97. screen:setColor("0xFFFF00")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement