Skip to content

Instantly share code, notes, and snippets.

@gschanuel
Created June 12, 2018 15:33
Show Gist options
  • Save gschanuel/7a85773a293c22d278c16de6843da7f1 to your computer and use it in GitHub Desktop.
Save gschanuel/7a85773a293c22d278c16de6843da7f1 to your computer and use it in GitHub Desktop.
function draw_graph (conky_value, table_length, radius, circle_width, table)
cairo_set_source_rgba(cr,rgb_to_r_g_b(color, alpha))
calculate_table(table_length, table)
for i = 1, table_length do
draw_line_in_circle(radius - (circle_width / 2), (circle_width / 100) * table[i], 4, (360 / table_length) * (i - 1), -1)
end
end
function calculate_table(table_length, table, conky_value)
for i = 1, table_length do
if table[i] == nil then
table[i] = 0
end
end
for i = table_length, 2, -1 do
table[i] = table[i - 1]
end
value = tonumber(conky_parse('${downspeedf eth0}')/100)
if value ~= nil then
table[1] = value
else
table[1] = 0
end
end
function draw_line_in_circle(offset, length, width, degree, r, g, b)
cairo_set_line_width(cr, width)
point = (math.pi / -180) * degree
start_x = 0 + (offset * math.sin(point))
start_y = 0 - (offset * math.cos(point))
end_x = 0 + ((offset + length) * math.sin(point))
end_y = 0 - ((offset + length) * math.cos(point))
cairo_move_to(cr, start_x + center_x, start_y + center_y)
cairo_line_to(cr, end_x + center_x, end_y + center_y)
cairo_set_source_rgb (cr, r, g, b);
cairo_stroke(cr)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment