font = text.loadfont("Victoria.8b.gif") Screen = require("screen") x_clock = 319 y_clock = 239 function _init(args) sys.stepinterval(1000/60) scrn = Screen:new("Nalquas' Clock Demo for Homegirl 0.6.2", 31, 8) --Mode31=640x480; 8 color bits scrn:colors(1, 0) --fg, bg scrn:palette(0,0,0,0) --background scrn:palette(1,15,15,15) --foreground and text end function _step(t) hour, minute, second, utc_offset = sys.time() year, month, date, weekday = sys.date() --Replace palette based on t in order to cycle through colors for i=0,15 do scrn:palette(i+2, clip(i*math.sin(t/1000.0), 0, 15), clip(i*math.sin((t-2000)/1000.0), 0, 15), clip(i*math.sin((t+2000)/1000.0), 0, 15)) end gfx.cls() --Dynamically adjust clock position, in case resizing of windows is impemented one day? x_clock, y_clock = scrn:size() x_clock = x_clock/2 y_clock = y_clock/2 --Render stripes for y=0,479 do gfx.fgcolor(10+round(7*math.sin((y/20)+(t/200)))) gfx.line(0,y,639,y) end --Render Clock Background/Circle gfx.fgcolor(1) for i=0,3599 do x_pix = x_clock+100*math.cos(math.rad(i/10)) y_pix = y_clock+100*math.sin(math.rad(i/10)) gfx.pixel(x_pix,y_pix,1) if i%900==0 then gfx.line(x_pix,y_pix,x_pix-10*math.cos(math.rad(i/10)),y_pix-10*math.sin(math.rad(i/10))) end end --Render Clock Hands --Hour (Shows progress of half-day) gfx.line(x_clock,y_clock,x_clock+65*math.cos(math.rad(((hour/12.0)*360)-90)),y_clock+65*math.sin(math.rad(((hour/12.0)*360)-90))) --Minutes (Shows progress of hour) gfx.line(x_clock,y_clock,x_clock+85*math.cos(math.rad(((minute/60.0)*360)-90)),y_clock+85*math.sin(math.rad(((minute/60.0)*360)-90))) --Seconds (Shows progress of minute) gfx.line(x_clock,y_clock,x_clock+95*math.cos(math.rad(((second/60.0)*360)-90)),y_clock+95*math.sin(math.rad(((second/60.0)*360)-90))) --Normalize digital clock text by adding zeros when appropriate text_time = {hour, minute, second} for i=1,#text_time do if #(text_time[i] .. "")==1 then text_time[i] = "0" .. text_time[i] end end --Normalize date text by adding zeros when appropriate text_date = {date, month, year} for i=1,2 do if #(text_date[i] .. "")==1 then text_date[i] = "0" .. text_date[i] end end gfx.fgcolor(1) text.draw(text_time[1] .. ":" .. text_time[2] .. ":" .. text_time[3], font, x_clock-31, y_clock+115) text.draw(text_date[1] .. "." .. text_date[2] .. "." .. text_date[3], font, x_clock-39, y_clock+130) --Check if we have to exit if input.hotkey() == "\x1b" then print("Thank you for experiencing this demo by Nalquas.") sys.exit(0) end scrn:step() end function clip(x, min, max) if xmax then x=max end return x end function round(x) if x<0 then return math.ceil(x-0.5) end return math.floor(x+0.5) end