Created
April 19, 2016 19:30
-
-
Save interactivenyc/2f5d48503e00133deb814e52e6bcebdf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setup() | |
LoadImages() --do this first, on its own | |
end | |
function LoadImages() | |
imageStatus='Ready' --tells draw it's ok to draw the scene (will be turned off if we have to download images) | |
output.clear() | |
--pass through Codea name of image and internet url | |
--not in Codea, will be downloaded and saved | |
img1=LoadImage('Dropbox:3D-tree', | |
'http://i1303.photobucket.com/albums/ag142/ignatz_mouse/map-tree27c_zpsd56f4f5f.png') | |
img2=LoadImage('SpaceCute:Background') | |
img3=LoadImage('Dropbox:3D-wall', | |
'http://i1303.photobucket.com/albums/ag142/ignatz_mouse/map-stonewall1_zps875ba0f0.png') | |
if imageStatus=='Ready' then setup2() end | |
end | |
--downloads images one by one | |
function LoadImage(fileName,url) | |
local i=readImage(fileName) | |
if i~=nil then return i end | |
--not found, we need to download, add to queue (ie table) | |
if imageTable==nil then imageTable={} end | |
imageTable[#imageTable+1]={name=fileName,url=url} | |
print('Queueing',fileName) | |
imageStatus='Loading' | |
--if the first one, go ahead and download | |
if #imageTable==1 then | |
http.request(imageTable[1].url,ImageDownloaded) | |
print('loading',imageTable[1].name) | |
end | |
end | |
--saves downloaded images | |
function ImageDownloaded(img) | |
print(imageTable[1].name,'loaded') | |
saveImage(imageTable[1].name,img) --save | |
table.remove(imageTable,1) | |
--load next one if we have any more to do | |
if #imageTable>0 then | |
http.request(imageTable[1].url,ImageDownloaded) | |
print('loading',imageTable[1].name) | |
else | |
LoadImages() | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment