Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python fu: Vector stroke scaling
#2
You have to define the "center" of the stroke Smile Is it the center of the bounding box? The center of mass/centroid? or something else? Once you have determined that, you compute the center for the before/after/strokes, compute the delta vector, and shift the stroke accordingly.

Note: the API to translate a stroke (stroke:translate() or its PDB equivalent) only shifts an integer amount of pixels, which makes it unusable in most cases. So you just construct a new stroke by adding the corresponding delta to all coordinates (anchors and tangents). A nice trick is to use a "cycle" generator:

Code:
offsets=itertools.cycle([translateX,translateY])
sourceCoords,closed=sourceStroke.points
translatedCoords=[coord+next(offsets) for coord in sourceCoords]
translatedStroke = gimp.VectorsBezierStroke(targetPath,translatedCoords,closed)

But your 2nd image makes me think that you don't want a scaled stroke, but the stroke which is "parallel" to the outer one, which is a different thing. If you tell me what you are trying to do I can find a way to do it differently. If you are on 2.10 there is however an indirect way to have Gimp create that path for you.
Reply


Messages In This Thread
Python fu: Vector stroke scaling - by awan - 08-24-2018, 04:04 PM
RE: Python fu: Vector stroke scaling - by Ofnuts - 08-24-2018, 04:57 PM
RE: Python fu: Vector stroke scaling - by awan - 08-24-2018, 06:01 PM
RE: Python fu: Vector stroke scaling - by Ofnuts - 08-24-2018, 07:18 PM
RE: Python fu: Vector stroke scaling - by awan - 08-25-2018, 04:38 AM
RE: Python fu: Vector stroke scaling - by Ofnuts - 08-25-2018, 08:16 AM

Forum Jump: