Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

a simple timer utility

Jmv38Jmv38 Mod
in Code Sharing Posts: 3,280

I needed a small timer for work
I though Codea could help
Here is the code


--# Bip Bip = class() function Bip:init(s,t,message) self.running = false self.delay = t self.sound = s self.message = message end function Bip:start() self.running = true self.time = ElapsedTime + self.delay end function Bip:play() if self.running and self.time < ElapsedTime then self.running = false if self.sound == 1 then sound(SOUND_BLIT, 45394) end if self.sound == 2 then sound("Game Sounds One:Pop 1") end if self.message then return(self.message) end end end --# Sequence Sequence = class() function Sequence:init(t) local t0 = 1.0 local t1 = t0 + t self.bip = {Bip(2, 0, "Ready..?"), Bip(2, t0, "3"), Bip(2, t0+0.5, "2"), Bip(2, t0+1, "1"), Bip(1, t0+1.5, "Press!"), Bip(2, t1, "3"), Bip(2, t1+0.5, "2"), Bip(2, t1+1, "1"), Bip(1, t1+1.5, "Release!")} self:resetMessage() end function Sequence:resetMessage() self.message = "Tap to start" end function Sequence:start() for i,bip in ipairs(self.bip) do bip:start() end end function Sequence:draw() local message for i,bip in ipairs(self.bip) do message = bip:play() if message then self.message = message end end if self.message then text(self.message, WIDTH/2,HEIGHT/2) end end function Sequence:touched(touch) self:start() end --# Main -- timer_00 -- Use this function to perform your initial setup function setup() print("Acquisition Timer") duration = 2.8 print("duration = "..duration.." s") seq = Sequence(2.8) 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) fontSize(100) fill(255, 218, 0, 255) -- Do your drawing here seq:draw() end function touched(t) if t.state==BEGAN then seq:start() end end
Sign In or Register to comment.