|
Script Coder |
|
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
|
|