Skip to content

Commit

Permalink
experiment with more clever aerographs #575
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Feb 3, 2023
1 parent 4e7c14e commit 9daaac4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
41 changes: 34 additions & 7 deletions src/tools/classic_tools/tool_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def __init__(self, window, **kwargs):
}
self._operator_label = "OVER"
self.operator2 = cairo.Operator.OVER
self._selected_mode = 'feather'
self._feather_dir = 'up'
self._selected_mode = 'aero2'

self.add_tool_action_enum('experiment_operator', self._operator_label)
self.add_tool_action_enum('experiment_mode', self._selected_mode)
Expand Down Expand Up @@ -168,11 +167,12 @@ def do_tool_operation(self, operation):
cairo_context.set_line_join(operation['line_join'])
cairo_context.set_source_rgba(*operation['rgba'])

if operation['mode'] == 'pressure':
if operation['is_preview']: # Previewing helps performance & debug
operation['line_width'] = int(operation['line_width'] / 2)
return self.op_simple(operation, cairo_context)
self.op_pressure(operation, cairo_context)
if operation['mode'] == 'aero1':
self.op_aerodots(operation, cairo_context)
elif operation['mode'] == 'aero2':
self.op_aerogradient(operation, cairo_context)
elif operation['mode'] == 'aero3':
self.op_aeroeraser(operation, cairo_context)
elif operation['mode'] == 'smooth':
if operation['is_preview']: # Previewing helps performance & debug
return self.op_simple(operation, cairo_context)
Expand All @@ -184,6 +184,33 @@ def do_tool_operation(self, operation):

############################################################################

def op_aeroeraser(self, operation, cairo_context):
self.op_aerodots(operation, cairo_context)

def op_aerodots(self, operation, cairo_context):
cairo_context.set_operator(operation['operator'])
cairo_context.new_path()
for pt in operation['path']:
radius = operation['line_width'] / 2
cairo_context.arc(pt['x'], pt['y'], radius, 0.0, 2 * math.pi)
cairo_context.fill()

def op_aerogradient(self, operation, cairo_context):
cairo_context.set_operator(operation['operator'])
cairo_context.new_path()
for pt in operation['path']:
radius = operation['line_width'] / 2
cairo_context.arc(pt['x'], pt['y'], radius, 0.0, 2 * math.pi)

pattern = cairo.RadialGradient(pt['x'], pt['y'], 0.1 * radius, \
pt['x'], pt['y'], 1.0 * radius)
[r, g, b, a] = operation['rgba']
pattern.add_color_stop_rgba(0.1, r, g, b, a)
pattern.add_color_stop_rgba(1.0, r, g, b, 0.0)
cairo_context.set_source(pattern)

cairo_context.fill()

def op_macro_w(self, operation, cairo_context):
"""Trying to study whatever tf is the rendering issue #337"""
cairo_context.set_antialias(cairo.Antialias.DEFAULT)
Expand Down
18 changes: 18 additions & 0 deletions src/tools/ui/tool-experiment.ui
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@
<attribute name="target">smooth</attribute>
</item>
</section>
<section>
<attribute name="label">Aérographes</attribute>
<item>
<attribute name="label">Aplats ronds</attribute>
<attribute name="action">win.experiment_mode</attribute>
<attribute name="target">aero1</attribute>
</item>
<item>
<attribute name="label">Pois en dégradés</attribute>
<attribute name="action">win.experiment_mode</attribute>
<attribute name="target">aero2</attribute>
</item>
<item>
<attribute name="label">Effaceur contextuel</attribute>
<attribute name="action">win.experiment_mode</attribute>
<attribute name="target">aero3</attribute>
</item>
</section>
<section>
<attribute name="label">Autres</attribute>
<item>
Expand Down

0 comments on commit 9daaac4

Please sign in to comment.