It is currently Thu Jul 04, 2024 5:25 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Gimp Python: Stroke Selection with Brush Dynamics
PostPosted: Tue Jan 03, 2017 5:55 pm  (#1) 
Offline
New Member

Joined: Jan 03, 2017
Posts: 3
Hi All,

I'm an experienced software developer for graphics, new to Gimp, but liking it more and more.

I'm looking for the Python pdb.* equivalent of the "Stroke Selection..." menu operation with the settings
"Stroke with a paint tool" and "Emulate brush dynamics". Is this a single function or is Gimp doing
several things here under the hood?

On a separate but related note, one of the leads I found on this topic was to convert the selection
to a path and then stroke that, but I found that the results when using bush dynamics are different
with the path from the selection. Can someone explain why that is?

Finally, I would also like to know how to edit the curves for a Paint Dynamics object programatically.
That would be emulating the functionality of the Paint Dynamics Editor, where you can select how
the velocity of the stroke affects the brush size (say) and actually edit the function curve that relates the
two parameters by adding and moving the control points.

Thanks, in advance, for any help here.
Clay Budin
NYC


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Gimp Python: Stroke Selection with Brush Dynamics
PostPosted: Tue Jan 03, 2017 7:18 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4756
As far as I can tell, Gimp uses the current brush dynamics(*) when it strokes the selection or a path, and the dynamics can be set using pdb.gimp_context_set_dynamics(name).

There is no API to "edit" dynamics, but you can create a file on the fly...

On the whole stroking a path usually gives a much cleaner result than stroking the selection if you are trying to make lines.

(*) at least for some input parameters: direction, random and fade, others don't really make sense when no human is involved.

_________________
Image


Top
 Post subject: Re: Gimp Python: Stroke Selection with Brush Dynamics
PostPosted: Wed Jan 04, 2017 10:24 am  (#3) 
Offline
New Member

Joined: Jan 03, 2017
Posts: 3
Hi,

Thanks for getting back to me. What I'm trying to do is to replicate in a Python script what
I see Gimp doing in its user interface. If I create a new image and make a simple selection (a
circle say), I can then choose "Edit->Stroke Selection..." and "Stroke with a paint tool" with
"Emulate brush dynamics" checked. Then it will draw the stroke and it will actually create values
for the pressure, velocity, direction and random parameters in the dynamics. I guess that it is
doing some kind of simulation of a user drawing action when it creates the stroke.

I am using pdb.gimp_edit_stroke() and it draws the stroke but it doesn't seem to simulate the
dynamics parameters like it does in the Gimp UI. The only parameters that seem to work are
fade and random.

Also, how can I load/save Paint Dynamics settings, as you mention? That would allow me to
animate the parameters over time, which I'd like to do.

Update: I found the dynamics file in ~/Library/Application Support/GIMP/2.8/dynamics/*.gdyn
as set in my Gimp Preferences. pdb.gimp_dynamics_refresh() appears to sync the file with the
settings in the UI (both directions).

Thanks,
Clay Budin
NYC


Top
 Post subject: Re: Gimp Python: Stroke Selection with Brush Dynamics
PostPosted: Wed Jan 04, 2017 12:40 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4756
You're right, the "direction" is not available. I'm quite sure it used to be there, so it could be a bug.

To load dynamics: pdb.gimp_context_set_dynamics(name).

_________________
Image


Top
 Post subject: Re: Gimp Python: Stroke Selection with Brush Dynamics
PostPosted: Thu Jan 05, 2017 11:22 am  (#5) 
Offline
New Member

Joined: Jan 03, 2017
Posts: 3
Hi,

I wanted to give an update on my progress and report what might be a bug.

I am now creating a Paint Dynamics file on the fly and loading it in with
pdb.gimp_dynamics_refresh() and making it active with
pdb.gimp_context_set_dynamics(). However, I'm finding that when I do
pdb.gimp_edit_stroke() on my layer with the selection, the stroke pattern
is not changing from frame to frame, even though I am changing the
Paint Dynamics file from frame to frame. I am using the Fade parameter
attached to the brush Size.

It looks like there is an issue with some kind of cache not updating when
the new Paint Dynamics files are read in. I can even see the same issue when
running GIMP through the UI. If I do a Stroke Selection in the UI I get the old
Fade-Size curve; if I go into the Paint Dynamics Editor window, bring up the
curve and click in the curve window - wham it changes to the new curve.

I've tried the following things to try to force it to update to the new curve:
- pdb.gimp_brushes_refresh()
- pdb.gimp_displays_flush()
- Removing the (n-samples 256) and (samples 256 ...) lines from the curve definition
in the Paint Dynamics file (in case that was acting as a cache)
- Switching the dynamics to a different one ("Dynamics Off") and then back to my
dynamics definition
- Creating multiple Paint Dynamics files, one for each frame, and switching to the
frame-specific one
- Delete the previous Paint Dynamics file leaving only a new one with changed curve

None of these have worked. If anyone has any other ideas, I would love to hear them.

Thanks,
Clay Budin
NYC


Top
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) stroke selection/stroke path

2

No new posts Attachment(s) Is there a script for doing Stroke outside selection?

4

No new posts Attachment(s) [solved] brush dynamics

8

No new posts Attachment(s) Quick Tutorial on Brush Dynamics: Specific Settings

11

No new posts Attachment(s) Board Game Design - Stroke Selection and Pattern Fill Questions

3



* Login  



Powered by phpBB3 © phpBB Group