vsketch
vsketch copied to clipboard
Feature: extensible stroke styling by passing callable to `vsk.strokeStyle()`
A way to easily apply stylistic modification to lines would generally be beneficial. Examples include emulating gritty-looking lines, brush-like strokes, etc.
Eventually, vpype would include a ready-to-use collection of such filters. In the mean time, a simple, callable-based filter mechanism might be useful and foster the development of filters that might be later integrated in vsketch.
def my_filter(line: np.ndarray, **kwargs) -> List[np.ndarray]:
# use `kwargs` as optional parameters for the algorithm
my_param = kwargs.getitem("my_param", 0.5)
# return one of more lines which represent the stylised version of the input line
lines = ...
return lines
vsk.stroke(1)
vsk.strokeStyle(my_filter, my_param=0.8) # remaining arguments are passed as kwargs to the callable
vsk.line(0, 0, 10, 10) # my_filter will be called with this line and the result will be added to the sketch
In the future, filters may be added to vsketch and referred to by a string:
vsk.strokeStyle("gritty", coarseness="3mm")
Wonderful idea!