blob: 431abd7ee324a1f8b98b5de80d27ade5de55442d [file] [log] [blame]
John Park91e69732019-03-03 13:12:43 -08001import cairo
2from color import Color, palette
John Park91e69732019-03-03 13:12:43 -08003import numpy as np
4
James Kuszmaul1c933e02020-03-07 16:17:51 -08005
John Park91e69732019-03-03 13:12:43 -08006def set_color(cr, color, a=1):
7 if color.a == 1.0:
8 cr.set_source_rgba(color.r, color.g, color.b, a)
9 else:
10 cr.set_source_rgba(color.r, color.g, color.b, color.a)
11
12
13def draw_px_cross(cr, x, y, length_px, color=palette["RED"]):
14 """Draws a cross with fixed dimensions in pixel space."""
15 set_color(cr, color)
16 cr.move_to(x, y - length_px)
17 cr.line_to(x, y + length_px)
18 cr.stroke()
19
20 cr.move_to(x - length_px, y)
21 cr.line_to(x + length_px, y)
22 cr.stroke()
23 set_color(cr, palette["WHITE"])
24
25
26def draw_px_x(cr, x, y, length_px1, color=palette["BLACK"]):
27 """Draws a x with fixed dimensions in pixel space."""
28 length_px = length_px1 / np.sqrt(2)
29 set_color(cr, color)
30 cr.move_to(x - length_px, y - length_px)
31 cr.line_to(x + length_px, y + length_px)
32 cr.stroke()
33
34 cr.move_to(x - length_px, y + length_px)
35 cr.line_to(x + length_px, y - length_px)
36 cr.stroke()
37 set_color(cr, palette["WHITE"])
38
James Kuszmaul1c933e02020-03-07 16:17:51 -080039
40def draw_circle(cr, x, y, radius, color=palette["RED"]):
John Parkcf545162020-02-23 20:07:25 -080041 set_color(cr, color)
James Kuszmaul1c933e02020-03-07 16:17:51 -080042 cr.arc(x, y, radius, 0, 2 * np.pi)
John Parkcf545162020-02-23 20:07:25 -080043 cr.fill()
44 cr.stroke()
John Park91e69732019-03-03 13:12:43 -080045
James Kuszmaul1c933e02020-03-07 16:17:51 -080046
John Park91e69732019-03-03 13:12:43 -080047def draw_control_points(cr, points, width=10, radius=4, color=palette["BLUE"]):
48 for i in range(0, len(points)):
49 draw_px_x(cr, points[i][0], points[i][1], width, color)
50 set_color(cr, color)
51 cr.arc(points[i][0], points[i][1], radius, 0, 2.0 * np.pi)
52 cr.fill()
53 set_color(cr, palette["WHITE"])
54
James Kuszmaul1c933e02020-03-07 16:17:51 -080055
John Park91e69732019-03-03 13:12:43 -080056def display_text(cr, text, widtha, heighta, widthb, heightb):
57 cr.scale(widtha, -heighta)
58 cr.show_text(text)
59 cr.scale(widthb, -heightb)
60
Ravago Jones5127ccc2022-07-31 16:32:45 -070061
John Park91e69732019-03-03 13:12:43 -080062def draw_points(cr, p, size):
63 for i in range(0, len(p)):
Ravago Jones5127ccc2022-07-31 16:32:45 -070064 draw_px_cross(cr, p[i][0], p[i][1], size,
65 Color(0, np.sqrt(0.2 * i), 0))