Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MAIN
- function setup()
- if readLocalData("exist")==nil then --first run
- Storage:FactoryDefaults()
- else
- Storage:Load()
- end
- weekday={
- [1]="Sunday",
- [2]="Monday",
- [3]="Tuesday",
- [4]="Wednesday",
- [5]="Thursday",
- [6]="Friday",
- [7]="Saturday"}
- month={
- [1]="January",
- [2]="February",
- [3]="March",
- [4]="April",
- [5]="May",
- [6]="June",
- [7]="July",
- [8]="August",
- [9]="September",
- [10]="October",
- [11]="November",
- [12]="December"}
- type={
- [1]="HelveticaNeue-CondensedBlack",
- [2]="GillSans-Light"}
- lineCapMode(ROUND)
- smooth()
- mode=FULLSCREEN
- displayMode(mode)
- textMode(CENTER)
- spriteMode(CORNER)
- fontSize(30)
- X=((WIDTH-Size)/2)+(Size/2)
- Y=((HEIGHT-Size)/2)+(Size/2)
- minutes=360/60
- hours=360/12
- seconds=360/60
- lastsecond=0
- AlarmRing=0
- Snoozing=0
- SnoozeStop=-1
- touched=nil
- SaveToggle=0
- end
- function graphics()
- background(Screen_Red,Screen_Green,Screen_Blue)
- font(type[Typeface])
- end
- function ResetStrokeFill()
- fill(Red,Green,Blue)
- tint(Red,Green,Blue,255)
- stroke(Screen_Red,Screen_Green,Screen_Blue)
- end
- function interface()
- if CurrentTouch.state==MOVING then
- X,Y=CurrentTouch.x,CurrentTouch.y
- end
- if CurrentTouch.state==ENDED then touched=nil end
- if CurrentTouch.state==BEGAN and touched==nil then
- if CurrentTouch.tapCount==2 then
- if mode==STANDARD then
- mode=FULLSCREEN
- else
- mode=STANDARD
- end
- displayMode(mode)
- touched=true
- end
- end
- end
- function SetAlarm(ATOD)
- strokeWidth(math.max((Size*.06),7))
- if Alarm_Switch==0 then
- stroke(Red,Green,Blue)
- fill(Screen_Red,Screen_Green,Screen_Blue)
- tint(Red,Green,Blue,0)
- end
- --Alarm Indicators
- textMode(CORNER)
- topline=(HEIGHT)-75
- sprite(bell:spriteimage(),30,topline+5,26,26)
- if Alarm_Minute<10 then
- minstr=":0"..Alarm_Minute.." "
- else
- minstr=":"..Alarm_Minute.." "
- end
- text(Alarm_Hour..minstr..ATOD,60,topline)
- textMode(CENTER)
- translate(X,Y)
- rotate(-((hours*Alarm_Hour)+((Alarm_Minute/60)*30)))
- line(0,(Size*.45),0,0+(Size*.45))
- resetMatrix()
- strokeWidth(0)
- ResetStrokeFill()
- end
- function RenderClock(thishour,thismin,thissec)
- --Ticks
- stroke(Screen_Red,Screen_Green,Screen_Blue)
- lineCapMode(SQUARE)
- tinytick=Size*.48
- tick=Size*.46
- tickmax=Size*.5
- if Size>=400 then
- strokeWidth(3)
- translate(X,Y)
- for i=1,360 do
- rotate(1)
- line(0,tinytick,0,tickmax) --tiny tick
- end
- resetMatrix()
- end
- if Size>=250 then
- strokeWidth(3)
- translate(X,Y)
- for i=1,60 do
- rotate(6)
- line(0,tick,0,tickmax) --minutes tick
- end
- resetMatrix()
- strokeWidth(5)
- translate(X,Y)
- for i=1,12 do
- rotate(30)
- line(0,tick,0,tickmax) --hours tick
- end
- resetMatrix()
- end
- lineCapMode(ROUND)
- --Second Hand
- strokeWidth(4)
- translate(X,Y)
- rotate(-(seconds*thissec))
- line(0,0,0,0+(Size*.5))
- if (lastsecond~=thissec) and (Ticking==1) then Sound:ticktock() end
- lastsecond=thissec
- resetMatrix()
- --Minute Hand
- strokeWidth(math.max((Size*.06),5))
- translate(X,Y)
- rotate(-(minutes*thismin))
- line(0,0,0,0+(Size*.38))
- resetMatrix()
- --Hour Hand
- translate(X,Y)
- rotate(-((hours*thishour)+((thismin/60)*30))) --Add "lean"
- strokeWidth(math.max((Size*.1),5))
- stroke(Red,Green,Blue)
- line(0,0,0,0+(Size*.25)) --outer ring
- strokeWidth(math.max((Size*.08),5))
- stroke(Screen_Red,Screen_Green,Screen_Blue)
- line(0,0,0,0+(Size*.25)) --hand
- resetMatrix()
- strokeWidth(0)
- ellipse(X,Y,Size*.05) --center stud
- ResetStrokeFill()
- end
- function TextDisplay(thishour,thismin,thissec,timeofday)
- if Text==0 then fill(Screen_Red,Screen_Green,Screen_Blue) end
- if thismin<10 then minstr=":0"..thismin else minstr=":"..thismin end
- if thissec<10 then secstr=":0"..thissec else secstr=":"..thissec end
- timenow=thishour..minstr..secstr.." "..timeofday.." "
- weekdaynow=weekday[now.wday]..", "
- datenow=month[now.month].." "..now.day.." "..now.year.." "
- daynow="Day "..now.yday
- text(timenow..weekdaynow..datenow..daynow,WIDTH/2,75)
- ResetStrokeFill()
- end
- function clock()
- now=os.date("*t") --seems this gets passed to TextDisplay
- thishour=now.hour
- thismin=now.min
- thissec=now.sec
- if thishour<12 then
- timeofday="AM"
- else
- timeofday="PM"
- if thishour>12 then thishour=thishour-12 end
- end
- ellipse(X,Y,Size,Size)
- if Alarm_Time_of_Day==0 then ATOD="AM" else ATOD="PM" end
- SetAlarm(ATOD)
- RenderClock(thishour,thismin,thissec)
- TextDisplay(thishour,thismin,thissec,timeofday)
- return thishour,thismin,thissec,timeofday,ATOD
- end
- function alarm(thishour,thismin,thissec,timeofday,ATOD)
- if Alarm_Switch==1 then
- if ATOD==timeofday then
- if Alarm_Hour==thishour then
- if Alarm_Minute==thismin then
- if AlarmRing==0 then AlarmRing=1 end
- end
- end
- end
- else
- AlarmRing,Snoozing=0,0
- end
- Snooze:manage(thismin,thissec)
- end
- -- This function gets called once every frame
- function draw()
- graphics()
- interface()
- alarm(clock())
- Storage:manage()
- end
- BELL TAB
- bell = class()
- function bell:spriteimage()
- local img = image(16, 16)
- img:set(1,3,255,255,255,255)
- img:set(2,3,255,255,255,255)
- img:set(2,4,255,255,255,255)
- img:set(3,3,255,255,255,255)
- img:set(3,4,255,255,255,255)
- img:set(3,5,255,255,255,255)
- img:set(4,3,255,255,255,255)
- img:set(4,4,255,255,255,255)
- img:set(4,5,255,255,255,255)
- img:set(4,6,255,255,255,255)
- img:set(4,7,255,255,255,255)
- img:set(4,8,255,255,255,255)
- img:set(5,3,255,255,255,255)
- img:set(5,4,255,255,255,255)
- img:set(5,5,255,255,255,255)
- img:set(5,6,255,255,255,255)
- img:set(5,7,255,255,255,255)
- img:set(5,8,255,255,255,255)
- img:set(5,9,255,255,255,255)
- img:set(5,10,255,255,255,255)
- img:set(5,11,255,255,255,255)
- img:set(5,12,255,255,255,255)
- img:set(5,13,255,255,255,255)
- img:set(5,14,255,255,255,255)
- img:set(6,3,255,255,255,255)
- img:set(6,4,255,255,255,255)
- img:set(6,5,255,255,255,255)
- img:set(6,6,255,255,255,255)
- img:set(6,7,255,255,255,255)
- img:set(6,8,255,255,255,255)
- img:set(6,9,255,255,255,255)
- img:set(6,10,255,255,255,255)
- img:set(6,11,255,255,255,255)
- img:set(6,12,255,255,255,255)
- img:set(6,13,255,255,255,255)
- img:set(6,14,255,255,255,255)
- img:set(6,15,255,255,255,255)
- img:set(7,1,255,255,255,255)
- img:set(7,2,255,255,255,255)
- img:set(7,3,255,255,255,255)
- img:set(7,4,255,255,255,255)
- img:set(7,5,255,255,255,255)
- img:set(7,6,255,255,255,255)
- img:set(7,7,255,255,255,255)
- img:set(7,8,255,255,255,255)
- img:set(7,9,255,255,255,255)
- img:set(7,10,255,255,255,255)
- img:set(7,11,255,255,255,255)
- img:set(7,12,255,255,255,255)
- img:set(7,13,255,255,255,255)
- img:set(7,14,255,255,255,255)
- img:set(7,15,255,255,255,255)
- img:set(8,1,255,255,255,255)
- img:set(8,2,255,255,255,255)
- img:set(8,3,255,255,255,255)
- img:set(8,4,255,255,255,255)
- img:set(8,5,255,255,255,255)
- img:set(8,6,255,255,255,255)
- img:set(8,7,255,255,255,255)
- img:set(8,8,255,255,255,255)
- img:set(8,9,255,255,255,255)
- img:set(8,10,255,255,255,255)
- img:set(8,11,255,255,255,255)
- img:set(8,12,255,255,255,255)
- img:set(8,13,255,255,255,255)
- img:set(8,14,255,255,255,255)
- img:set(8,15,255,255,255,255)
- img:set(9,1,255,255,255,255)
- img:set(9,2,255,255,255,255)
- img:set(9,3,255,255,255,255)
- img:set(9,4,255,255,255,255)
- img:set(9,5,255,255,255,255)
- img:set(9,6,255,255,255,255)
- img:set(9,7,255,255,255,255)
- img:set(9,8,255,255,255,255)
- img:set(9,9,255,255,255,255)
- img:set(9,10,255,255,255,255)
- img:set(9,11,255,255,255,255)
- img:set(9,12,255,255,255,255)
- img:set(9,13,255,255,255,255)
- img:set(9,14,255,255,255,255)
- img:set(9,15,255,255,255,255)
- img:set(10,3,255,255,255,255)
- img:set(10,4,255,255,255,255)
- img:set(10,5,255,255,255,255)
- img:set(10,6,255,255,255,255)
- img:set(10,7,255,255,255,255)
- img:set(10,8,255,255,255,255)
- img:set(10,9,255,255,255,255)
- img:set(10,10,255,255,255,255)
- img:set(10,11,255,255,255,255)
- img:set(10,12,255,255,255,255)
- img:set(10,13,255,255,255,255)
- img:set(10,14,255,255,255,255)
- img:set(10,15,255,255,255,255)
- img:set(11,3,255,255,255,255)
- img:set(11,4,255,255,255,255)
- img:set(11,5,255,255,255,255)
- img:set(11,6,255,255,255,255)
- img:set(11,7,255,255,255,255)
- img:set(11,8,255,255,255,255)
- img:set(11,9,255,255,255,255)
- img:set(11,10,255,255,255,255)
- img:set(11,11,255,255,255,255)
- img:set(11,12,255,255,255,255)
- img:set(11,13,255,255,255,255)
- img:set(11,14,255,255,255,255)
- img:set(12,3,255,255,255,255)
- img:set(12,4,255,255,255,255)
- img:set(12,5,255,255,255,255)
- img:set(12,6,255,255,255,255)
- img:set(12,7,255,255,255,255)
- img:set(12,8,255,255,255,255)
- img:set(13,3,255,255,255,255)
- img:set(13,4,255,255,255,255)
- img:set(13,5,255,255,255,255)
- img:set(14,3,255,255,255,255)
- img:set(14,4,255,255,255,255)
- img:set(15,3,255,255,255,255)
- return img
- end
- SNOOZE TAB
- Snooze = class()
- function Snooze:manage(thismin,thissec)
- --Start Snooze? Swipe to Start
- if AlarmRing==1 then
- if CurrentTouch.state==MOVING and Snoozing==0 then
- Snoozing=1
- SnoozeStop=thismin+Snooze_Time+(thissec/60)
- if SnoozeStop>59.99 then SnoozeStop=SnoozeStop-60 end
- end
- end
- --Is Snooze done?
- if SnoozeStop==thismin+(thissec/60) then
- Snoozing=0
- SnoozeStop=-1 --reset
- end
- if AlarmRing==1 and Snoozing==0 then Sound:alarm() end
- end
- SOUND TAB
- Sound = class()
- function Sound:alarm()
- sound(DATA, "ZgBAOwBAQEBAQEBAy5IJPvClpj4AAIA/SwBAf0BAQEBAQEBA")
- sound(DATA, "ZgJAAAAAAAAAAAB5nc2zuwAAgD8AAAAAAAAAAAAAAD8AAEAA")
- end
- function Sound:ticktock()
- if AlarmRing==1 and Snoozing==0 then
- else
- sound(DATA, "ZgFAf1cAf39/f39pAAAAAOU1lD4AAAAAAAB/f39/AEB/AD1/")
- end
- end
- STORAGE TAB
- Storage = class()
- function Storage:manage()
- if SaveToggle~=Toggle_Save then
- SaveToggle=Toggle_Save
- self.Save()
- end
- if Reset_Factory_Defaults==1 then --not working right
- -- clearLocalData()
- mode=FULLSCREEN
- displayMode(mode)
- clearParameters()
- self.FactoryDefaults()
- self.Save() --shouldn't be necessary
- ResetStrokeFill()
- end
- end
- function Storage:FactoryDefaults()
- iparameter("Toggle_Save",0,1,0)
- iparameter("Reset_Factory_Defaults",0,1,0)
- iparameter("Size",150,700,525)
- iparameter("Ticking",0,1,1)
- iparameter("Text",0,1,1)
- iparameter("Typeface",1,2,1)
- iparameter("Screen_Red",0,255,0)
- iparameter("Screen_Green",0,255,0)
- iparameter("Screen_Blue",0,257,0)
- iparameter("Red",0,255,255)
- iparameter("Green",0,255,180)
- iparameter("Blue",0,255,0)
- iparameter("Alarm_Switch",0,1,1)
- iparameter("Alarm_Hour",1,12,5)
- iparameter("Alarm_Minute",0,59,0)
- iparameter("Alarm_Time_of_Day",0,1,0)
- iparameter("Snooze_Time",0,20,10)
- end
- function Storage:Save()
- saveLocalData("exist",true)
- saveLocalData("ipSize",Size)
- saveLocalData("ipTicking",Ticking)
- saveLocalData("ipText",Text)
- saveLocalData("ipTypeface",Typeface)
- saveLocalData("ipScreen_Red",Screen_Red)
- saveLocalData("ipScreen_Green",Screen_Green)
- saveLocalData("ipScreen_Blue",Screen_Blue)
- saveLocalData("ipRed",Red)
- saveLocalData("ipGreen",Green)
- saveLocalData("ipBlue",Blue)
- saveLocalData("ipAlarm_Switch",Alarm_Switch)
- saveLocalData("ipAlarm_Hour",Alarm_Hour)
- saveLocalData("ipAlarm_Minute",Alarm_Minute)
- saveLocalData("ipATOD",ATOD)
- saveLocalData("ipSnooze_Time",Snooze_Time)
- end
- function Storage:Load()
- iparameter("Toggle_Save",0,1,0)
- iparameter("Reset_Factory_Defaults",0,1,0)
- iparameter("Size",150,700,readLocalData("ipSize"))
- iparameter("Ticking",0,1,readLocalData("ipTicking"))
- iparameter("Text",0,1,readLocalData("ipText"))
- iparameter("Typeface",1,2,readLocalData("ipTypeface"))
- iparameter("Screen_Red",0,255,readLocalData("ipScreen_Red"))
- iparameter("Screen_Green",0,255,readLocalData("ipScreen_Green"))
- iparameter("Screen_Blue",0,257,readLocalData("ipScreen_Blue"))
- iparameter("Red",0,255,readLocalData("ipRed"))
- iparameter("Green",0,255,readLocalData("ipGreen"))
- iparameter("Blue",0,255,readLocalData("ipBlue"))
- iparameter("Alarm_Switch",0,1,readLocalData("ipAlarm_Switch"))
- iparameter("Alarm_Hour",1,12,readLocalData("ipAlarm_Hour"))
- iparameter("Alarm_Minute",0,59,readLocalData("ipAlarm_Minute"))
- iparameter("Alarm_Time_of_Day",0,1,readLocalData("ipATOD"))
- iparameter("Snooze_Time",0,20,readLocalData("ipSnooze_Time"))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement