Debian Codegraph @

src/tools/classic_tools/brushes/brush_airbrush.py

raw symbols SCIP
1 # Licensed under GPL3 https://github.com/maoschanz/drawing/blob/master/LICENSE
2
3 import cairo, random
4 from .abstract_brush import AbstractBrush
5
6 class BrushAirbrush(AbstractBrush):
7 __gtype_name__ = 'BrushAirbrush'
8
9 def _get_tips(self, use_pressure, brush_direction):
10 label = _("Airbrush") + " - "
11 if use_pressure:
12 label += _("Density depends on the stylus pressure")
13 else:
14 label += _("Density depends on the mouse speed")
15 return [label]
16
17 def do_brush_operation(self, cairo_context, operation):
18 """Airbrush whose radius is the line width. The density of droplets is
19 related to the stylus pressure."""
20
21 cairo_context.set_operator(operation['operator'])
22 cairo_context.set_source_rgba(*operation['rgba'])
23
24 # if operation['is_preview']: # Previewing helps performance & debug
25 # operation['line_width'] = int(operation['line_width'] / 2)
26 # return self.draw_preview(operation, cairo_context)
27
28 cairo_context.set_line_width(1)
29 random.seed(1) # this hardcoded seed avoids the droplets changing their
30 # positions when the user undoes an following operation
31 half_width = int(operation['line_width'] / 2)
32 droplets = 20 # could be like 15 + log(width) maybe?
33
34 for pt in operation['path']:
35 if pt['p'] is not None:
36 droplets = int(40 * pt['p'])
37 for i in range(droplets):
38 cairo_context.new_path()
39 x = pt['x'] + random.randint(-1 * half_width, half_width)
40 y = pt['y'] + random.randint(-1 * half_width, half_width)
41 cairo_context.move_to(x, y)
42 cairo_context.rel_line_to(1, 1)
43 cairo_context.stroke()
44 # XXX the pattern is square, not round
45
46 ############################################################################
47 ################################################################################
48