Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Main
- -- App 07 - Image I/O http
- -- Bruce Elliott
- -- May 2013
- --Built from Image I/O example
- function setup()
- ----------------------------------------------------
- -- 2. Now we'll download our logo into an image
- logo = nil -- it's empty for now
- -- Start the request, didGetLogo is our callback function
- http.request( "http://twolivesleft.com/logo.png", didGetLogo )
- ---------------------------------------------------
- -- Once the image downloads we use makeCircleImage()
- -- to make a copy of the image then
- -- we save the image to Dropbox or Documents
- ---------------------------------------------------
- -- 4. Now let's list the images in Documents
- print("Sprites contained in 'Documents'")
- local list = spriteList( "Dropbox" )
- for _,v in pairs(list) do
- print(v)
- end
- print("")
- ---------------------------------------------------
- end
- function makeCircleImage()
- -- This function makes a red circle
- -- Renders it into an image, and returns the image
- -- We exapanded the size of img to screen sizep
- local img = image(WIDTH, HEIGHT)
- ------------------------------------
- -- Use the image as a render target
- setContext(img)
- background(0,0,0,0) -- transparent background
- fill(255,0,0)
- -- We draw the sprite to img instead of the screen
- sprite( logo, WIDTH/2, HEIGHT/2, WIDTH )
- -- ellipse(200,200,200)
- -- Set render target back to screen
- setContext()
- ------------------------------------
- return img
- end
- function didGetLogo( theLogo, status, headers )
- print( "Response Status: " .. status )
- -- Store logo in our global variable
- logo = theLogo
- -- Check if the status is OK (200)
- if status == 200 then
- print( "Downloaded logo OK" )
- print( " Image dimensions: " ..
- logo.width .. "x" .. logo.height )
- -- Call makeCircle once image was downloaded
- img = makeCircleImage()
- -- Save to Dropbox or Documents or both
- saveImage("Dropbox:Logo", img)
- saveImage("Documents:Logo", img)
- else
- print( "Error downloading logo" )
- end
- end
- -- This function gets called once every frame
- function draw()
- -- This sets a dark background color
- background(40, 40, 50)
- -- Draw the logo we downloaded (when it's ready!)
- if logo ~= nil then
- sprite(img, WIDTH/2, HEIGHT/2, WIDTH )
- end
- -- Draw the circle image we saved and read from the sprite pack
- -- sprite( circleImage, WIDTH/2, 110 )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement