Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sin = math.sin
- cos = math.cos
- rad = math.rad
- WEEKDAYS = {"MON","TUE","WED","THU","FRI","SAT","SUN"}
- MONTHS = {"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"}
- function arc(x, y, a, b, r, t)
- ellipseMode(CENTER)
- noStroke()
- -- arc using ellipse
- r = (r-t)/2 - 1
- local s = dial
- for i = rad(a), rad(b), 1/s do
- ellipse(x+r*cos(i), y+r*sin(i), t+1,t+1)
- end
- end
- function cal2deg(val, div)
- return 90 - (360/div) * val
- end
- function deg2cal(degree, r)
- r = r/2 - 1
- mx = r * cos(rad(degree))
- my = r * sin(rad(degree))
- return mx, my
- end
- function getLocalDateTime()
- return os.date("*t")
- end
- function setColor(r, g, b, a)
- fill(r, g, b, a)
- stroke(r, g, b, a)
- end
- function sweep()
- if last_sec == second then
- sweepStep = sweepStep + 1
- else
- maxStep = sweepStep + 1
- sweepStep = 0
- last_sec = second
- end
- end
- function drawTick(div, r, t)
- ellipseMode(CENTER)
- setColor(0, 0, 0, 255)
- -- tick marks
- for i = 0, 359, 360/div do
- local tx, ty = deg2cal(90-i, r)
- ellipse(x+tx, y+ty, t)
- end
- end
- function drawDial()
- ellipseMode(CENTER)
- noFill()
- strokeWidth(thick)
- -- rainbow color
- stroke(48, 0, 48, 255)
- ellipse(x,y,inner+1*dial)
- stroke(32, 0, 64, 255)
- ellipse(x,y,inner+2*dial)
- stroke(0, 0, 64, 255)
- ellipse(x,y,inner+3*dial)
- stroke(0, 64, 0, 255)
- ellipse(x,y,inner+4*dial)
- stroke(64, 64, 0, 255)
- ellipse(x,y,inner+5*dial)
- stroke(64, 32, 0, 255)
- ellipse(x,y,inner+6*dial)
- stroke(64, 0, 0, 255)
- ellipse(x,y,inner+7*dial)
- stroke(128, 128, 128, 255)
- ellipse(x,y,thick)
- strokeWidth(space)
- stroke(128, 128, 128, 255)
- ellipse(x,y,inner+7*dial+4*space)
- -- tick mark
- drawTick( 10,inner+1*dial-thick,thick/5)
- drawTick( 12,inner+2*dial-thick,thick/5)
- drawTick(days,inner+3*dial-thick,thick/5)
- drawTick( 7,inner+4*dial-thick,thick/5)
- drawTick( 12,inner+5*dial-thick,thick/5)
- drawTick( 60,inner+6*dial-thick,thick/5)
- drawTick( 60,inner+7*dial-thick,thick/5)
- end
- function drawValue()
- textMode(CORNER)
- --font("DB LCD Temp")
- font("Courier-Bold")
- fontSize(thick/2)
- local w,h = textSize("0")
- fill(48, 0, 48, 255)
- text(dt.sec,x,y+4*dial-thick/2+h/2-space)
- fill(32, 0, 64, 255)
- text(dt.min,x,y+3.5*dial-thick/2+h/2-space)
- fill(0, 0, 64, 255)
- text(dt.hour,x,y+3*dial-thick/2+h/2-space)
- fill(0, 64, 0, 255)
- text(WEEKDAYS[dt.wday],x,y+2.5*dial-thick/2+h/2-space)
- fill(64, 64, 0, 255)
- text(dt.day,x,y+2*dial-thick/2+h/2-space)
- fill(64, 32, 0, 255)
- text(MONTHS[dt.month],x,y+1.5*dial-thick/2+h/2-space)
- fill(64, 0, 0, 255)
- text(2000+dt.year,x,y+1*dial-thick/2+h/2-space)
- end
- function setup()
- print("RADIAL CALENDAR")
- print("Started: "..os.date())
- x = WIDTH/2
- y = HEIGHT/2
- thick = 30
- space = thick/10
- inner = 2*(thick+space)+thick
- dial = 2*(thick+space)
- last_sec = getLocalDateTime().sec
- sweepStep = 0
- maxStep = 30
- --watch("sweepStep")
- watch("maxStep")
- --watch("second")
- watch("days")
- iparameter("thick",10,50,thick)
- iparameter("space",1,10,space)
- end
- function draw()
- days = 31
- background(0)
- noSmooth()
- drawDial()
- frame_rate = 30-DeltaTime*30
- inner = 2*(thick+space)+thick
- dial = 2*(thick+space)
- -- read and adjust datetime
- dt = getLocalDateTime()
- second = dt.sec
- hour = dt.hour
- if hour >= 12 then hour = hour - 12 end
- dt.wday = dt.wday - 1
- if dt.wday == 0 then dt.wday = 7 end
- if dt.month % 2 == 0 then days = 30 else days = 31 end
- if dt.month == 2 then
- if dt.year % 4 == 0 then days = 29 else days = 28 end
- end
- if dt.year >= 2000 then dt.year = dt.year - 2000 end
- sweep()
- noStroke()
- strokeWidth(0)
- -- time
- setColor(255, 0, 0, 255)
- arc(x,y,cal2deg(dt.sec+sweepStep/maxStep,60),90,inner+7*dial,thick)
- --arc(x,y,cal2deg(dt.sec,60), 90,inner+7*dial,thick)
- setColor(255, 128, 0, 255)
- arc(x,y,cal2deg(dt.min + dt.sec/60,60), 90,inner+6*dial,thick)
- setColor(255, 255, 0, 255)
- arc(x,y,cal2deg(hour + dt.min/60,12), 90,inner+5*dial,thick)
- -- day
- setColor(0, 255, 0, 255)
- arc(x,y,cal2deg(dt.wday-1 + dt.hour/24,7), 90,inner+4*dial,thick)
- -- date
- setColor(0, 0, 255, 255)
- arc(x,y,cal2deg(dt.day-1 + dt.hour/24,days), 90,inner+3*dial,thick)
- setColor(128, 0, 255, 255)
- arc(x,y,cal2deg(dt.month-1 + dt.day/days,12),90,inner+2*dial,thick)
- setColor(128, 0, 128, 255)
- arc(x,y,cal2deg(dt.year-1 + dt.month/12,100),90,inner+1*dial,thick)
- --drawValue()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement