Advertisement
br1wr2el3

Code 11 - Camera Demo

May 26th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. --# Main
  2. -- Code 11 - Camera Demo
  3. -- Camera
  4. -- A significant amount of this code (all but three lines in takePhoto)
  5. -- was provided in the Codea example program Camera
  6. -- My thanks to that author
  7.  
  8. -- Bruce Elliott
  9. -- April 2013
  10.  
  11. -- Use this function to perform your initial setup
  12. function setup()
  13. print("This example shows you how to use camera input")
  14.  
  15. -- Create a couple buttons for our camera source
  16. parameter.action("Front Camera", front)
  17.  
  18. parameter.action("Back Camera", function()
  19. cameraSource(CAMERA_BACK)
  20. end)
  21.  
  22. parameter.action("Take Photo", takePhoto)
  23.  
  24.  
  25.  
  26.  
  27. -- Start using the front camera
  28. cameraSource(CAMERA_FRONT)
  29.  
  30.  
  31. -- A variable to hold our captured photo
  32. capturedImage = nil
  33. end
  34.  
  35. function takePhoto()
  36. -- Date as unique filename
  37. -- yr mo da hr min sec
  38. thisdate = os.date("%y%m%d%H%M%S")
  39.  
  40. --Setuo to store in Dropbox
  41. imgName = "Dropbox:img"..thisdate
  42.  
  43. -- Store image
  44. capturedImage = image(CAMERA)
  45.  
  46. -- Save the image
  47. saveImage(imgName, capturedImage)
  48.  
  49. end
  50.  
  51. -- This function gets called once every frame
  52. function draw()
  53. -- This sets a dark background color
  54. background(40, 40, 50)
  55.  
  56. -- This sets the line thickness
  57. strokeWidth(5)
  58.  
  59.  
  60. -- Get the size of the current camera texture
  61. local camWidth, camHeight = spriteSize( CAMERA)
  62. -- Draw the special CAMERA sprite
  63. sprite( CAMERA, WIDTH/2, HEIGHT/2, math.min( camWidth, WIDTH ) )
  64.  
  65. -- Draw our captured image if available
  66. if capturedImage ~= nil then
  67. pushStyle()
  68. spriteMode(CORNER)
  69. sprite(capturedImage, WIDTH/2 - 100, 0, 200)
  70. popStyle()
  71. end
  72. end
  73.  
  74. function front()
  75. print("front")
  76. cameraSource(CAMERA_FRONT)
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement