Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Main
- -- Code 11 - Camera Demo
- -- Camera
- -- A significant amount of this code (all but three lines in takePhoto)
- -- was provided in the Codea example program Camera
- -- My thanks to that author
- -- Bruce Elliott
- -- April 2013
- -- Use this function to perform your initial setup
- function setup()
- print("This example shows you how to use camera input")
- -- Create a couple buttons for our camera source
- parameter.action("Front Camera", front)
- parameter.action("Back Camera", function()
- cameraSource(CAMERA_BACK)
- end)
- parameter.action("Take Photo", takePhoto)
- -- Start using the front camera
- cameraSource(CAMERA_FRONT)
- -- A variable to hold our captured photo
- capturedImage = nil
- end
- function takePhoto()
- -- Date as unique filename
- -- yr mo da hr min sec
- thisdate = os.date("%y%m%d%H%M%S")
- --Setuo to store in Dropbox
- imgName = "Dropbox:img"..thisdate
- -- Store image
- capturedImage = image(CAMERA)
- -- Save the image
- saveImage(imgName, capturedImage)
- end
- -- This function gets called once every frame
- function draw()
- -- This sets a dark background color
- background(40, 40, 50)
- -- This sets the line thickness
- strokeWidth(5)
- -- Get the size of the current camera texture
- local camWidth, camHeight = spriteSize( CAMERA)
- -- Draw the special CAMERA sprite
- sprite( CAMERA, WIDTH/2, HEIGHT/2, math.min( camWidth, WIDTH ) )
- -- Draw our captured image if available
- if capturedImage ~= nil then
- pushStyle()
- spriteMode(CORNER)
- sprite(capturedImage, WIDTH/2 - 100, 0, 200)
- popStyle()
- end
- end
- function front()
- print("front")
- cameraSource(CAMERA_FRONT)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement