abey79 / vsketch

Generative plotter art environment for Python
https://vsketch.readthedocs.io/en/latest/
Other
492 stars 50 forks source link

Feature: extensible stroke styling by passing callable to `vsk.strokeStyle()` #206

Open abey79 opened 2 years ago

abey79 commented 2 years ago

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")
hapiel commented 2 years ago

Wonderful idea!