Skip to content

Instantly share code, notes, and snippets.

@gschanuel
Created June 13, 2018 18:46
Show Gist options
  • Save gschanuel/805f410dfe01faf1a7c50a5da849085d to your computer and use it in GitHub Desktop.
Save gschanuel/805f410dfe01faf1a7c50a5da849085d to your computer and use it in GitHub Desktop.
function draw_graph (conky_value, table_length, radius, circle_width, table, line_width)
-- calculate table
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(conky_value))
if value ~= nil then
table[1] = value
else
table[1] = 0
end
-- end calculate table
for i = 1, table_length do
-- draw_line_in_circle(radius - (circle_width / 2), (circle_width / 100) * table[i], line_width, (360 / table_length) * (i - 1), start )
draw_line_in_circle(radius - (circle_width / 2), (circle_width / 100) * table[i], line_width, (360 / table_length) * (i - 1), (circle_width * table[i]) )
end
end
function draw_line_in_circle(offset, length, width, degree, circle_width)
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))
end_xp = 0 + (offset + circle_width) * math.sin(point)
end_yp = 0 - (offset + circle_width) * math.cos(point)
-- p = cairo_pattern_create_linear(start_x + center_x, start_y + center_y, end_x + center_x, end_y + center_y)
p = cairo_pattern_create_linear(start_x + center_x, start_y + center_y, end_xp - center_x, end_yp - center_y)
cairo_pattern_add_color_stop_rgb(p, 0, 0, 1, 0)
-- cairo_pattern_add_color_stop_rgb(p, 0.6, 0, 1, 0)
cairo_pattern_add_color_stop_rgb(p, 1, 1, 0, 0)
cairo_set_source(cr, p)
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, 0, 0, 50);
cairo_stroke(cr)
cairo_pattern_destroy(p);
end
@gschanuel
Copy link
Author

function draw_graph (conky_value, table_length, radius, circle_width, table, line_width)
-- calculate table
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(conky_value))

    if value ~= nil then
            table[1] = value
    else
            table[1] = 0
    end
    -- end calculate table

    for i = 1, table_length do

-- draw_line_in_circle(radius - (circle_width / 2), (circle_width / 100) * table[i], line_width, (360 / table_length) * (i - 1), start )
draw_line_in_circle(radius - (circle_width / 2), (circle_width / 100) * table[i], line_width, (360 / table_length) * (i - 1), circle_width )
end
end

function draw_line_in_circle(offset, length, width, degree, circle_width)

    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))
    end_xp = 0 + (offset + circle_width) * math.sin(point)
    end_yp = 0 - (offset + circle_width) * math.cos(point)

-- p = cairo_pattern_create_linear(start_x + center_x, start_y + center_y, end_x + center_x, end_y + center_y)
p = cairo_pattern_create_linear(start_x + center_x, start_y + center_y, end_xp + center_x, end_yp + center_y)

    cairo_pattern_add_color_stop_rgb(p, 0, 0, 1, 0)

-- cairo_pattern_add_color_stop_rgb(p, 0.6, 0, 1, 0)
cairo_pattern_add_color_stop_rgb(p, 1, 1, 0, 0)
cairo_set_source(cr, p)

    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, 0, 0, 50);
    cairo_stroke(cr)

    cairo_pattern_destroy(p);

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment