Skip to content

Instantly share code, notes, and snippets.

@SimonVanherweghe
Last active March 20, 2024 10:15
Show Gist options
  • Save SimonVanherweghe/fd741b90fa4063c222b690a42d3d171a to your computer and use it in GitHub Desktop.
Save SimonVanherweghe/fd741b90fa4063c222b690a42d3d171a to your computer and use it in GitHub Desktop.
A vpype script to inlcude a dipping pattern in a plotter svg
# The colors available
eval "colorNames = ['red','green','blue','darkbrown','yellow','blue','purple']"
# Position of the colors, assuming they are in a grid (x: column, y: row)
eval "colorPosition = [{'x':0,'y':0},{'x':1,'y':0},{'x':2,'y':0},{'x':3,'y':0},{'x':0,'y':1},{'x':1,'y':1},{'x':2,'y':1}]"
# width en height of the colors, postion of water cup (center), radius of water cup
eval "colorWidth = 15; colorHeight = 20; nStrokes=0; waterX = 150; waterY = 20; waterR=5"
# How much distance can a brush cover before it needs new paint
eval "length = float(input('Maximum stroke length in cm [15]? ') or 15)"
# No need to dip in the water before every paint dip (aquarel)
eval "waterTreshold = float(input('Amount of strokes before water dip [10]? ') or 10)"
# for every layer in te original file
forlayer
lmove %_lid% 1
# get te position of the color
eval "colorIndex = colorNames.index(_name)"
eval "colorLocation = colorPosition[colorIndex]"
eval "xpos=colorLocation['x'];ypos=colorLocation['y']"
# split as much lines as possible
splitall
splitdist %length%cm
linemerge
# for every part (splitted line)
forlayer
lmove %_lid% "%_lid*2%"
# do we need to dip in the water?
eval "rest = nStrokes %% waterTreshold"
eval "nWaterDips = 3 if rest==0 else 0"
repeat %nWaterDips%
ellipse -l '%_lid*2-1%' %waterX%mm %waterY%mm %waterR%mm %waterR%mm
end
# dip in the color
repeat 3
ellipse -l "%_lid*2-1%" %xpos*colorWidth+(colorWidth/2)%mm %ypos*colorHeight+(colorHeight/2)-_i%mm %colorWidth*0.2%mm %colorHeight*0.3-_i%mm
end
# make it slightly random
squiggles -l "%_lid*2-1%" -a 2mm
# keep track of strokes
eval "nStrokes += 1"
end
eval "nStrokes=0";
# move them all back in the original layer
lmove all %_lid%
# bookkeeping
name -l %_lid% %_name%
color -l %_lid% %_color%
end
write output.svg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment