It is currently 19 Feb 2018, 19:48

GIMP Script RequestsEmulate brush dynamics on stroke (Showcase | Slideshow)

Post your Script Requests for GIMP here.
Forum rules
Request your Script(s) for GIMP here in this forum.
Provide details of steps performed in GIMP so that script can be written for the process and also give the request a name so that scripts can be named after.
Post Reply
User avatar
RJKD

Tutorial Creator
View: Showcase | Slideshow
Topic Posts: 1/2
Posts: 1351
Joined: 03 Oct 2016, 13:01
Cash on hand: 10,313.98 GLP
Bank: 0.00 GLP
Gender: Guy
Location: Sheffield UK
Operating System: Windows
GIMP Version: 2.8.20
x 1488
x 209
Contact:
Great Britain

Emulate brush dynamics on stroke

Post#1 by RJKD » 16 Oct 2017, 19:33


I am following http://gimpchat.com/viewtopic.php?f=8&t ... 30c51204a6 with much anticipation.
I would like to be able to stroke a path with pressure opacity at one end of a the stroke only (fade/taper doesn't achieve my required outcome).
Currently pressure opacity is applied to the start and end of a stroke.
Big ask.
0 x




Registered members enjoy ads-free content
User avatar
tim
Administrator
View: Showcase | Slideshow
Topic Posts: 1/2
Posts: 2157
Joined: 26 Sep 2016, 00:16
Cash on hand: 7,894.01 GLP
Bank: 51,356.25 GLP
Gender: Guy
Location: Victoria, BC
Website: https://gimplearn.net
Operating System: Windows
GIMP Version: 2.8.22
My Personal Blog
My FineArtAmerica
x 1200
x 256
Contact:
Canada

Post#2 by tim » 16 Oct 2017, 19:58


I was able to get it to fadeout with the below sample code.

Code: Select all

#!/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("2. Hardness 100")

	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
		points = []
		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.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,100,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()
fade_on_start_of_path_through_script.jpg
fade_on_start_of_path_through_script.jpg # (13.21 KiB) Viewed 236 times (Watermarked | Thumbnail)
I don't know how to do it through GIMP's GUI though.
1 x



aka Tin
Image gimplearn.net                                              

Post Reply

Last 20 Members Who Visited This Topic

User avatar Pat625 (3), User avatar leopardo-40 (1), User avatar gnerd (2), User avatar RJKD (2), User avatar dinasset (1), User avatar Conbagui (1), User avatar tim (6)

  • Similar Topics
    Replies
    Views
    Last post
• Featuring Members' Works (Image Attachments Only) •
1: Ella
2: tim
3: Conbagui
4: Ella
5: RJKD
6: Pat625
7: david

Who is online

Users browsing this forum: pmig and 1 guest