Advertisement
dlm955

clock3.lua

Dec 2nd, 2011
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. --[[
  2. Air Clock by Alison Pitt (2009)
  3.  
  4. This clock is designed to look like KDE 4.3's "Air" clock, but from inside Conky.
  5.  
  6. You can adjust the clock's radius and placement, as well as the size and offset of the drop shadow. You can also choose whether to display the seconds hand. This clock updates every time Conky does, so if you want to show seconds, it is recommended that you set update_interval to no more than 0.5s. If you turn off seconds, you can set the update_interval to as long as 30s. The settings are in the "Settings" section, starting at Line 21.
  7.  
  8. Call this script in Conky using the following before TEXT (assuming you save this script to ~/scripts/clock.lua):
  9. lua_load ~/scripts/clock.lua
  10. lua_draw_hook_pre draw_clock
  11. ]]
  12.  
  13. require 'cairo'
  14. function conky_draw_clock()
  15. if conky_window==nil then return end
  16. local w=conky_window.width
  17. local h=conky_window.height
  18. local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
  19. cr=cairo_create(cs)
  20.  
  21. -- Settings
  22.  
  23. -- What radius should the clock face (not including border) be, in pixels?
  24.  
  25. local clock_r=60
  26.  
  27. -- x and y coordinates, relative to the top left corner of Conky, in pixels
  28.  
  29. local xc=w/2
  30. local yc=h/10.5
  31.  
  32. -- Extent of the shadow, in pixels
  33.  
  34. shadow_width=35
  35.  
  36. -- x and y offsets of the drop shadow, relative to the centre of the clock face, in pixels. Can be positive (downward) or negative (upward)
  37.  
  38. shadow_xoffset=0
  39. shadow_yoffset=0
  40.  
  41. -- Do you want to show the second hand? Use this if you use a Conky update_interval > 1s. Can be true or false.
  42.  
  43. show_seconds=true
  44.  
  45. -- Grab time
  46.  
  47. local hours=os.date("%I")
  48. local mins=os.date("%M")
  49. local secs=os.date("%S")
  50.  
  51. secs_arc=(2*math.pi/60)*secs
  52. mins_arc=(2*math.pi/60)*mins
  53. hours_arc=(2*math.pi/12)*hours+mins_arc/12
  54.  
  55. -- Drop shadow
  56.  
  57. local ds_pat=cairo_pattern_create_radial(xc+shadow_xoffset,yc+shadow_yoffset,clock_r*1.25,xc+shadow_xoffset,yc+shadow_yoffset,clock_r*1.25+shadow_width)
  58. cairo_pattern_add_color_stop_rgba(ds_pat,0.5,0.9,0.9,0.9,0)
  59. cairo_pattern_add_color_stop_rgba(ds_pat,0,0.5,0.9,0.9,0.9)
  60.  
  61. cairo_move_to(cr,0,0)
  62. cairo_line_to(cr,w,0)
  63. cairo_line_to(cr,w,h)
  64. cairo_line_to(cr,0,h)
  65. cairo_new_sub_path(cr)
  66. cairo_arc(cr,xc,yc,clock_r*1.25,0,2*math.pi)
  67. cairo_set_source(cr,ds_pat)
  68. cairo_set_fill_rule(cr,CAIRO_FILL_RULE_EVEN_ODD)
  69. cairo_fill(cr)
  70.  
  71. -- Glassy border
  72.  
  73. cairo_arc(cr,xc,yc,clock_r*1.25,0,2*math.pi)
  74. cairo_set_source_rgba(cr,0.5,0.9,0.9,0.9)
  75. cairo_set_line_width(cr,4)
  76. cairo_stroke(cr)
  77.  
  78. local border_pat=cairo_pattern_create_linear(xc,yc-clock_r*1.25,xc,yc+clock_r*1.25)
  79.  
  80. cairo_pattern_add_color_stop_rgba(border_pat,0,1,1,1,0.6)
  81. cairo_pattern_add_color_stop_rgba(border_pat,0.3,1,1,1,0)
  82. cairo_pattern_add_color_stop_rgba(border_pat,0.5,1,1,1,0)
  83. cairo_pattern_add_color_stop_rgba(border_pat,0.7,1,1,1,0)
  84. cairo_pattern_add_color_stop_rgba(border_pat,1,1,1,1,0.3)
  85. cairo_set_source(cr,border_pat)
  86. cairo_arc(cr,xc,yc,clock_r*1.125,0,2*math.pi)
  87. cairo_close_path(cr)
  88. cairo_set_line_width(cr,clock_r*0.25)
  89. cairo_stroke(cr)
  90.  
  91. -- Set clock face
  92.  
  93. cairo_arc(cr,xc,yc,clock_r,0,2*math.pi)
  94. cairo_close_path(cr)
  95.  
  96. local face_pat=cairo_pattern_create_radial(xc,yc-clock_r*0.0,0,xc,yc,clock_r)
  97.  
  98. cairo_pattern_add_color_stop_rgba(face_pat,0.3,0,9,9,0.2)
  99. cairo_pattern_add_color_stop_rgba(face_pat,0.6,0,9,9,0.4)
  100. cairo_pattern_add_color_stop_rgba(face_pat,0.9,0,9,9,0.5)
  101. cairo_set_source(cr,face_pat)
  102. cairo_fill_preserve(cr)
  103. cairo_set_source_rgba(cr,0.5,0.9,0.9,0.9)
  104. cairo_set_line_width(cr, 2)
  105. cairo_stroke (cr)
  106.  
  107. -- Draw hour hand
  108.  
  109. xh=xc+0.7*clock_r*math.sin(hours_arc)
  110. yh=yc-0.7*clock_r*math.cos(hours_arc)
  111. cairo_move_to(cr,xc,yc)
  112. cairo_line_to(cr,xh,yh)
  113.  
  114. cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND)
  115. cairo_set_line_width(cr,5)
  116. cairo_set_source_rgba(cr,0,0,0,0.9)
  117. cairo_stroke(cr)
  118.  
  119. -- Draw minute hand
  120.  
  121. xm=xc+0.9*clock_r*math.sin(mins_arc)
  122. ym=yc-0.9*clock_r*math.cos(mins_arc)
  123. cairo_move_to(cr,xc,yc)
  124. cairo_line_to(cr,xm,ym)
  125.  
  126. cairo_set_line_width(cr,3)
  127. cairo_stroke(cr)
  128.  
  129. -- Draw seconds hand
  130.  
  131. if show_seconds then
  132. xs=xc+0.9*clock_r*math.sin(secs_arc)
  133. ys=yc-0.9*clock_r*math.cos(secs_arc)
  134. cairo_move_to(cr,xc,yc)
  135. cairo_line_to(cr,xs,ys)
  136.  
  137. cairo_set_line_width(cr,1)
  138. cairo_stroke(cr)
  139. end
  140. end
  141.  
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement