sugar-toolkit-gtk3/sugar/chat/sketchpad/Sketch.py

35 lines
821 B
Python
Raw Normal View History

2006-05-19 20:18:41 +02:00
from SVGdraw import path
2006-05-19 18:45:08 +02:00
class Sketch:
2006-05-22 04:21:42 +02:00
def __init__(self, rgb):
2006-05-19 18:45:08 +02:00
self._points = []
2006-05-22 04:21:42 +02:00
self._rgb = (float(rgb[0]), float(rgb[1]), float(rgb[2]))
2006-05-19 18:45:08 +02:00
def add_point(self, x, y):
2006-05-22 04:21:42 +02:00
self._points.append((x, y))
2006-05-19 18:45:08 +02:00
def draw(self, ctx):
start = True
2006-05-22 04:21:42 +02:00
for (x, y) in self._points:
2006-05-19 18:45:08 +02:00
if start:
ctx.move_to(x, y)
start = False
else:
ctx.line_to(x, y)
2006-05-22 04:21:42 +02:00
ctx.set_source_rgb(self._rgb[0], self._rgb[1], self._rgb[2])
2006-05-19 18:45:08 +02:00
ctx.stroke()
2006-05-19 20:18:41 +02:00
def draw_to_svg(self):
i = 0
2006-05-22 04:21:42 +02:00
for (x, y) in self._points:
2006-05-19 20:18:41 +02:00
coords = str(x) + ' ' + str(y) + ' '
if i == 0:
path_data = 'M ' + coords
elif i == 1:
path_data += 'L ' + coords
else:
path_data += coords
i += 1
2006-05-22 04:21:42 +02:00
color = "#%02X%02X%02X" % (255 * self._rgb[0], 255 * self._rgb[1], 255 * self._rgb[2])
return path(path_data, fill = 'none', stroke = color)