Time lapse pictures

Here’s a program that will let you take time lapse pictures. There is a “start time”, a “stop time”, and an “interval tme”. There is also a “max” set at 5 to prevent you from filling up your Dropbox with pictures. You can change that value to anything you want. There’s a “blank screen” option that allows you to blank the screen while doing time lapse. The options are n or y. To start the time lapse after setting the times, set the “Start” to a y. After the time is up, the input screen will show. There’s a “view” to let you see your pictures, set that to a y. You can see each picture one at a time by tapping the screen or view them as a movie by moving your finger on the screen. Tap EXIT VIEW at the top of the screen to return to the input screen. There is a “delete” that will remove only the time lapse pictures from the Dropbox folder, set that to a y. Tap any input field and enter a value. There is no need to press RETURN. If you make a mistake, just tap the input field again and re-enter the value. Once you enter a y in the Start field, the time will start. To take time lapse starting before midnight and ending after midnight, set the “stop time” to a value greater than 24 and set “max” to a value that will take the correct amount of pictures for your interval and the time you want to take. I tried to check everything, but if you run into any problems let me know. You may have to change Auto-Lock in Settings/General to a value greater than the Interval time to prevent the iPad from turning off before the time lapse is done.

EDIT: You can delete the pictures manually from the Dropbox folder. The pictures are named starting with pics# followed by the hour- minute- second that the image was taken.


supportedOrientations(LANDSCAPE_ANY)

function setup()
    parameter.watch("picsTaken")   
    rectMode(CENTER)
    cameraSource(CAMERA_BACK)  
    img=image(CAMERA)
    tm=os.date("*t")
    delay=5
    rest=false
    create=false
    view=false
    error=false
    start=false
    offset=1
    picsTaken=0
    picTime=0
    viewTab={}
    tab={}
    table.insert(tab,input(250,700,50,30,0,"Start Hour"))    
    table.insert(tab,input(450,700,50,30,0,"Start minute"))
    table.insert(tab,input(250,630,50,30,23,"Stop hour"))
    table.insert(tab,input(450,630,50,30,59,"Stop minute"))   
    table.insert(tab,input(200,560,50,30,0,"Interval Hour"))  
    table.insert(tab,input(350,560,50,30,0,"Interval minute"))  
    table.insert(tab,input(500,560,50,30,0,"Interval seconds"))   
    table.insert(tab,input(200,490,50,30,5,"Max pics"))  
    table.insert(tab,input(350,490,50,30,"n","Blank screen (n/y)"))  
    table.insert(tab,input(500,490,50,30,"n","Start (n/y)"))  
    table.insert(tab,input(120,420,50,30,"n","View (n/y)"))  
    table.insert(tab,input(250,420,50,30,"n","Delete (n/y)"))      
    tab[1].str=tm.hour
    tab[2].str=tm.min
end

function draw()
    background(0)
    tm=os.date("*t")
    checkInput()
    if start and not error then
        local startTime=tab[1].str*3600+tab[2].str*60
        local stopTime=tab[3].str*3600+tab[4].str*60
        local currTime=tm.hour*3600+tm.min*60+tm.sec
        local intervalTime=tab[5].str*3600+tab[6].str*60+tab[7].str
        if intervalTime==0 then
            start=false
            return
        end
        if currTime>=startTime and currTime<stopTime then
            if picTime==0 then
                picTime=currTime+intervalTime             
            end
            if currTime==picTime then
                picTime=picTime+intervalTime
                takePicture()               
            end
        elseif picsTaken>0 then
            rest=true
        end
        img=image(CAMERA)
        if img~=nil and tab[9].str=="n" then
            sprite(img,WIDTH/2,HEIGHT/2)
        end
    elseif create then
        local sl=spriteList("Dropbox")
        for a,b in pairs(sl) do
            if string.sub(b,1,5)=="pics#" then
                table.insert(viewTab,readImage("Dropbox:"..b))
            end
        end
        create=false
        view=true
        print("Pictures to view  "..#viewTab)
    elseif view then
        if #viewTab==0 then
            restart()
        else
            sprite(viewTab[offset],WIDTH/2,HEIGHT/2)
            fill(255,0,0)
            text("EXIT VIEW",WIDTH/2,HEIGHT-25)
        end
    else
        fill(211, 223, 177, 255)
        stroke(255,0,0)
        strokeWidth(10)
        rect(350,560,600,400)
        fill(255)
        noStroke()
        for nbr,inp in pairs(tab) do
            inp:draw()
        end
        fill(0, 12, 255, 255)
        local ct=string.format("Current time  %02d:%02d:%02d",tm.hour,tm.min,tm.sec)
        text(ct,450,440)
        text("Tap on an area to change the value.",450,400)
    end
    if rest then
        delay=delay-1
        if delay<0 then
            restart()
        end
    end
end

function takePicture()
    if picsTaken<tab[8].str then
        picsTaken=picsTaken+1
        local key=string.format("Dropbox:pics#%d-%d-%d",tm.hour,tm.min,tm.sec)
        saveImage(key,img)
        print(key)
    elseif picsTaken>=tab[8].str then
        rest=true
    end
end

function keyboard(k)
    for nbr,inp in pairs(tab) do
        inp:keyboard(k)
    end
end

function touched(t)
    if view then
        if t.state==BEGAN or t.state==MOVING then
            offset=offset+1
            if offset>#viewTab then
                offset=1
            end
        end
        if t.state==ENDED and t.y>HEIGHT-50 then
            restart()
        end
    else
        for nbr,inp in pairs(tab) do
            inp:touched(t)
        end  
    end
end

function checkInput()
    error=false
    for z=1,#tab-4 do
        if type(tab[z].str)~="number" then
            start=false
            error=true
        end
    end
end

function deleteView()
    local sl=spriteList("Dropbox")
    for a,b in pairs(sl) do
        if string.sub(b,1,5)=="pics#" then
            saveImage("Dropbox:"..b,nil)
        end
    end
    restart()
end

input = class()

function input:init(x,y,w,h,val,txt)
    self.x=x; self.y=y; self.width=w; self.height=h
    self.left=x-self.width/2; self.right=x+self.width/2;
    self.bottom=y-self.height/2; self.top=y+self.height/2
    self.color=color(120, 203, 225, 255)
    self.str=val
    self.selected=false
    self.start=txt
end

function input:draw()
    if self.selected then
        fill(255)
    else
        fill(self.color)
    end
    rect(self.x,self.y,self.width,self.height)
    if self.str~="" then
        fill(0)
        text(self.str,self.x,self.y)
    end
    fill(246, 27, 27, 255)
    text(self.start,self.x,self.y+self.height/2+9)
end

function input:touched(t)
    if t.state==BEGAN then
        if not isKeyboardShowing() then
            showKeyboard()
        end
        if t.x>self.left and t.x<self.right then
            if t.y>self.bottom and t.y<self.top then
                for nbr,inp in pairs(tab) do
                    inp.selected=false
                end                
                self.selected=true
                self.str=""          
            end
        end
    end
end

function input:keyboard(k)
    if self.selected then
        self.str=self.str..k
        if self.str>="0" and self.str<="999" then
            self.str=tonumber(self.str)
        elseif tab[10].str=="y" then
            start=true
            hideKeyboard()
        elseif tab[11].str=="y" then
            create=true
            hideKeyboard()
        elseif tab[12].str=="y" then
            deleteView()
        end
    end
end

@dave1707 - interesting!

http://www.studioneat.com/blogs/main/15467765-how-does-the-ios-8-time-lapse-feature-work

@dave1707 - When iOS8 has added time lapse to the photo app, I noticed that it doesn’t ask you to set any durations, you simply start it, then stop it when you want. So I was wondering how it did that, ie how it sets the interval between photos without knowing in advance what it will be.

I’m guessing that it takes a certain number of pictures at short intervals, and if you keep going, it extends the intervals and drops out the unwanted photos in between. The intervals might need to be in powers of two, perhaps, doubling as the time extends.

That would be a nice little challenge for you, to make all your parameters unnecessary!

@Ignatz But that’s the whole point. I start when I want, I stop when I want. I take pictures at the interval that I want. Apple does what they want and you’re supposed to like it. I haven’t loaded iOS8 yet, and I’ll wait for them to get all their bugs out before I do.

I guess I’m a minimalist, I prefer the Apple approach of “it just works”, rather than having to fiddle around entering all the details.

@Ignatz But then how do you start and stop it if you happen to be sleeping. What happens if you want the images at a specific time interval. I guess I’m just the opposite. I want full control and I don’t want someone else making the decisions for me.

dave+1

It’s ok, but I was just wondering how they do it, that’s all. It’s pretty clever.

@Ignatz what your thoughts about IOS8? My friend dont like it because of bugs

@lupino8211 - my iPad3 seems a bit slower, and Codea occasionally makes the iPad close entirely. I haven’t seen any real improvements, so I probably agree with dave1707, to wait a bit…

@lupino8211 @Ignatz I would wait for iOS 8.1, iOS 8 bricked me and my dad’s iPads (requiring restoring to factory settings, losing all data), and I’ve seen it happening to other people online.

@Ignatz @SkyTheCoder i think the perfect IOS was IOS6 . Now , for example,my safari crashing randomly in 30 minutes - 1 hour period . I updated my ipad to ios7 only for codea

The user and all related content has been deleted.