| 1 |
|
| 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 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
cairo_context.set_line_width(1) |
| 29 |
random.seed(1) |
| 30 |
|
| 31 |
half_width = int(operation['line_width'] / 2) |
| 32 |
droplets = 20 |
| 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 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|