It is currently Fri Apr 26, 2024 8:20 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Stroke with paint tool
PostPosted: Sat Oct 14, 2017 8:18 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
GIMP Version: 2.8.22
Operating System: Windows
GIMP Experience: Basic Level

List any relevant plug-ins or scripts:
gimp-edit-stroke-vectors

List any ERROR messages you received:
none



Is there, or is planned to have it soon in std Gimp, the possibility to stroke paths with the options available interactively "stroke with a paint tool"?
Or: is there a plug-in doing that?
Thanks.

_________________
"Where am I ?"


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: Stroke with paint tool
PostPosted: Sat Oct 14, 2017 5:31 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
It's already there... pdb.gimp_edit_stroke_vectors(drawable, vectors). Parameters are taken from the context (gimp-context-{get|set}-*'. The paint tool is selected with pdb.gimp_context_set_paint_method(name). The thing that is really missing is painting in "Line" mode.

_________________
Image


Top
 Post subject: Re: Stroke with paint tool
PostPosted: Sat Oct 14, 2017 6:32 pm  (#3) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
Yeah, the stroke line is what is missing.
That's why I had to find code to generate .svg paths then turn load the .svg.
That's the only way i know how to simulate stroke line for now. It does a pretty good job i think.

_________________
TinT


Top
 Post subject: Re: Stroke with paint tool
PostPosted: Sun Oct 15, 2017 12:20 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
ofnuts wrote:
It's already there... pdb.gimp_edit_stroke_vectors(drawable, vectors). Parameters are taken from the context (gimp-context-{get|set}-*'. The paint tool is selected with pdb.gimp_context_set_paint_method(name). The thing that is really missing is painting in "Line" mode.

Thanks a lot, Ofnuts, I couldn't identify this possibility.

_________________
"Where am I ?"


Top
 Post subject: Re: Stroke with paint tool
PostPosted: Sun Oct 15, 2017 3:42 am  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
(2nd reply)
Ofnuts, I tried and I could set the paint_method, but how can I set also what's available interactively "emulate brush dynamics"? I setted the dynamics to "Track Direction".
My try was using the "pepper" brush and I wanted to see the brush "rotate" following the path as it's possible interactively, but I didn't succeed.

_________________
"Where am I ?"


Top
 Post subject: Re: Stroke with paint tool
PostPosted: Sun Oct 15, 2017 3:15 pm  (#6) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
I can't get Track Direction to work either.
But here's a work around if you can't find out how to Emulate Brush Dynamics.
#!/usr/bin/env python

# sample.py Rel 1
# Created by Tin Tran
# Comments directed to https://gimplearn.net
#
# License: GPLv3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY# without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release
from gimpfu import *
import math
#========================================
#Copied this below function from ofnuts text-along-path-0.4.py
def computeThetaWithSlope(fromPoint,toPoint,slope):
   dX=toPoint[0]-fromPoint[0]
   dY=toPoint[1]-fromPoint[1]

   if math.fabs(dX) < .001:
      theta=math.copysign(math.pi/2,dY)
   else:
      theta=math.atan(slope)
      if dX<0:
         theta=theta+math.pi
   return theta
#========================================

def python_sample(image, layer) : #FUNCTION DEFINITION
   pdb.gimp_image_undo_group_start(image)
   pdb.gimp_context_push()
   #YOUR CODE BEGINS=======================
   pdb.gimp_message("Hello World")
   vectors = pdb.gimp_image_get_active_vectors(image)
   pdb.gimp_context_set_brush("z Pepper")

   pdb.gimp_context_set_dynamics("Track Direction") #Doesn't seem to take effect at all when we try to stroke vectors
   num_strokes, stroke_ids = pdb.gimp_vectors_get_strokes(vectors)
   paint_between_length = 15;
   for i in range(0,num_strokes):
      stroke_length = pdb.gimp_vectors_stroke_get_length(vectors,stroke_ids[i],0.01)
      dist_at = 1
      while dist_at <= stroke_length:
         x1,y1,slope,valid = pdb.gimp_vectors_stroke_get_point_at_dist(vectors,stroke_ids[i],dist_at-1,0.01)
         x2,y2,slope,valid = pdb.gimp_vectors_stroke_get_point_at_dist(vectors,stroke_ids[i],dist_at,0.01)
         x3,y3,slope,valid = pdb.gimp_vectors_stroke_get_point_at_dist(vectors,stroke_ids[i],dist_at+1,0.01)
         
         points = []
         points.append(x2)
         points.append(y2)
         dist_at += paint_between_length
         angle = computeThetaWithSlope([x1,y1],[x3,y3],slope) #calculate angle based on slope
         #angle_out = pdb.gimp_brush_set_angle("Tin_test",angle/2/math.pi * 360)
         angle = angle/2/math.pi * 360
         if angle > 180:
            angle -= 360
         pdb.gimp_context_set_brush_angle(angle)
         #pdb.gimp_message(angle_out)
         pdb.gimp_paintbrush(layer,0,len(points),points,PAINT_CONSTANT,0)
   #pdb.gimp_brush_delete("Tin_test")
   #YOUR CODE ENDS ========================
   pdb.gimp_context_pop()
   pdb.gimp_image_undo_group_end(image)
   pdb.gimp_displays_flush()
    #return

register(
   "python_fu_sample",
   "Sample Python Fu Script",
   "Sample Python Fu Script...",
   "Tin Tran",
   "Tin Tran",
   "Oct 2017",
   "<Image>/Python-Fu/Sample...",
   "*",      # Create a new image, don't work on an existing one
   [
   #INPUT BEGINS
   #(PF_OPTION, "arrow_side", "Arrows Ends:", SIDE_END, SIDE_NAMES),
   #(PF_TOGGLE, "arrow_close", "Arrows Close:", 0),
   #(PF_SPINNER, "border_width", "Border Width (bevelled width):", 10, (0, 500, 1)),
   #(PF_SPINNER, "shadow_offset_x", "Shadow Offset X:", 6, (-4096,4096,1)),
   #(PF_SPINNER, "shadow_offset_y", "Shadow Offset Y:", 6, (-4096,4096,1)),
   #(PF_SPINNER, "shadow_blur_radius", "Shadow Blur Radius:", 15, (0,1024,1)),
   #(PF_SPINNER, "shadow_opacity", "Shadow Opacity:", 100, (0,100,1)),
   #INPUT ENDS
   ],
   [],
   python_sample)

main()


computeThetaWithSlope is ofnuts code i found in his path script, I use it in my "custom font on path script" and it works great...
The work around basically get points on the path and then paint every point after getting points on path and you have slope which is used to calculate angle.

PS. Ofnuts says there's a better function "Better function in ofn-text-along-path... uses the overlooked math.atan2()" so you might want to look for that. I would starting now.

here's code that uses the "better" version of ofnuts code.
#!/usr/bin/env python

# sample.py Rel 1
# Created by Tin Tran
# Comments directed to https://gimplearn.net
#
# License: GPLv3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY# without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release
from gimpfu import *
import math
# ======================================================================
#Copied this from ofnuts' ofn-text-along-path.py
def computeOrientedSlope(dx,dy,slope): #This is a better version than below computeThetaWithSlope function.
   if abs(slope) > 100000: # very vertical
      return math.atan2(dy,dx) # no perfect, but properly oriented
        # keep dx/dy signs but give then the same ratio as in slope
   return math.atan2(math.copysign(slope,dy),math.copysign(1,dx))
# ======================================================================
def python_sample(image, layer) : #FUNCTION DEFINITION
   pdb.gimp_image_undo_group_start(image)
   pdb.gimp_context_push()
   #YOUR CODE BEGINS=======================
   pdb.gimp_message("Hello World")
   vectors = pdb.gimp_image_get_active_vectors(image)
   pdb.gimp_context_set_brush("z Pepper")

   pdb.gimp_context_set_dynamics("Track Direction") #Doesn't seem to take effect at all when we try to stroke vectors
   num_strokes, stroke_ids = pdb.gimp_vectors_get_strokes(vectors)
   paint_between_length = 15;
   for i in range(0,num_strokes):
      stroke_length = pdb.gimp_vectors_stroke_get_length(vectors,stroke_ids[i],0.01)
      dist_at = 1
      while dist_at <= stroke_length:
         x1,y1,slope,valid = pdb.gimp_vectors_stroke_get_point_at_dist(vectors,stroke_ids[i],dist_at-1,0.01)
         x2,y2,slope,valid = pdb.gimp_vectors_stroke_get_point_at_dist(vectors,stroke_ids[i],dist_at,0.01)
         x3,y3,slope,valid = pdb.gimp_vectors_stroke_get_point_at_dist(vectors,stroke_ids[i],dist_at+1,0.01)
         
         points = []
         points.append(x2)
         points.append(y2)
         dist_at += paint_between_length
         angle = computeOrientedSlope(x3-x1,y3-y1,slope) #calculate angle based on slope
         #angle_out = pdb.gimp_brush_set_angle("Tin_test",angle/2/math.pi * 360)
         angle = angle/2/math.pi * 360
         if angle > 180:
            angle -= 360
         pdb.gimp_context_set_brush_angle(angle)
         #pdb.gimp_message(angle_out)
         pdb.gimp_paintbrush(layer,0,len(points),points,PAINT_CONSTANT,0)
   #pdb.gimp_brush_delete("Tin_test")
   #YOUR CODE ENDS ========================
   pdb.gimp_context_pop()
   pdb.gimp_image_undo_group_end(image)
   pdb.gimp_displays_flush()
    #return

register(
   "python_fu_sample",
   "Sample Python Fu Script",
   "Sample Python Fu Script...",
   "Tin Tran",
   "Tin Tran",
   "Oct 2017",
   "<Image>/Python-Fu/Sample...",
   "*",      # Create a new image, don't work on an existing one
   [
   #INPUT BEGINS
   #(PF_OPTION, "arrow_side", "Arrows Ends:", SIDE_END, SIDE_NAMES),
   #(PF_TOGGLE, "arrow_close", "Arrows Close:", 0),
   #(PF_SPINNER, "border_width", "Border Width (bevelled width):", 10, (0, 500, 1)),
   #(PF_SPINNER, "shadow_offset_x", "Shadow Offset X:", 6, (-4096,4096,1)),
   #(PF_SPINNER, "shadow_offset_y", "Shadow Offset Y:", 6, (-4096,4096,1)),
   #(PF_SPINNER, "shadow_blur_radius", "Shadow Blur Radius:", 15, (0,1024,1)),
   #(PF_SPINNER, "shadow_opacity", "Shadow Opacity:", 100, (0,100,1)),
   #INPUT ENDS
   ],
   [],
   python_sample)

main()

_________________
TinT


Top
 Post subject: Re: Stroke with paint tool
PostPosted: Sun Oct 15, 2017 10:32 pm  (#7) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Thanks Tin.
I'll try to embed this in my tests.

_________________
"Where am I ?"


Top
 Post subject: Re: Stroke with paint tool
PostPosted: Sun Oct 15, 2017 11:26 pm  (#8) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Tried, it works fine.
Thanks again, Tin.

_________________
"Where am I ?"


Top
 Post subject: Re: Stroke with paint tool
PostPosted: Mon Oct 16, 2017 11:15 am  (#9) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
Cool.

_________________
TinT


Top
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Recalling FPS (Free Paint Stroke)

79

No new posts Edit stroke made by pencil tool

3

No new posts An issue with the paint brush tool

3

No new posts Stroke: how to remove space between test & stroke

3

No new posts Attachment(s) stroke selection/stroke path

2


cron

* Login  



Powered by phpBB3 © phpBB Group