fixed spirograph to work with textext; some cleanings in colorize paths

This commit is contained in:
Mario Voigt 2021-05-15 15:35:30 +02:00
parent 4e9301c8de
commit ed10bf466d
3 changed files with 71 additions and 62 deletions

View File

@ -3,16 +3,17 @@
<name>Colorize Path Lengths</name> <name>Colorize Path Lengths</name>
<id>fablabchemnitz.de.pathselection</id> <id>fablabchemnitz.de.pathselection</id>
<param name="selection" type="optiongroup" appearance="combo" gui-text="Selection: "> <param name="selection" type="optiongroup" appearance="combo" gui-text="Selection: ">
<option value="Path_lengthselection">Length_selection</option> <option value="path_lengthselection">Length selection</option>
<option value="Path_slantselection">Slant_selection</option> <option value="path_slantselection">Slant selection</option>
</param> </param>
<param name="len1" type="float" gui-text="Len1: red &lt; (px)" min="1" max="100">12</param> <label>Unit for lengths is px</label>
<param name="len1" type="float" gui-text="Len1: red &lt;" min="1" max="100">12</param>
<param name="len2" type="float" gui-text="Len2: green &lt; =" min="1" max="100">25</param> <param name="len2" type="float" gui-text="Len2: green &lt; =" min="1" max="100">25</param>
<param name="len3" type="float" gui-text="Len3: greenyellow &lt; =" min="1" max="100">40</param> <param name="len3" type="float" gui-text="Len3: greenyellow &lt; =" min="1" max="100">40</param>
<param name="len4" type="float" gui-text="Len4: skyblue &lt; =" min="1" max="100">60</param> <param name="len4" type="float" gui-text="Len4: skyblue &lt; =" min="1" max="100">60</param>
<param name="len5" type="float" gui-text="Len5: blue &gt; " min="1" max="100">60</param> <param name="len5" type="float" gui-text="Len5: blue &gt;" min="1" max="100">60</param>
<param name="hor" type="float" gui-text="hor: red &lt; (H/W)" min="0.01" max="100">0.1</param> <param name="hor" type="float" gui-text="hor: red &lt; (H/W)" min="0.01" max="100">0.1</param>
<param name="ver" type="float" gui-text="ver: blue &gt; " min="1" max="100">10</param> <param name="ver" type="float" gui-text="ver: blue &gt;" min="1" max="100">10</param>
<effect> <effect>
<object-type>path</object-type> <object-type>path</object-type>
<effects-menu> <effects-menu>

View File

@ -69,62 +69,70 @@ class Length(inkex.EffectExtension):
def effect(self): def effect(self):
# loop over all selected paths # loop over all selected paths
if self.options.selection=="Path_lengthselection": if self.options.selection=="path_lengthselection":
for id, node in self.svg.selected.items(): if len(self.svg.selected) > 0:
if node.tag == inkex.addNS('path','svg'): for node in self.svg.selected.values():
l1,l2,l3,l4,l5=[],[],[],[],[] if node.tag == inkex.addNS('path','svg'):
p = paths.CubicSuperPath(inkex.paths.Path(node.get('d'))) l1,l2,l3,l4,l5=[],[],[],[],[]
slengths= csplength(p) p = paths.CubicSuperPath(inkex.paths.Path(node.get('d')))
b=[slengths, p] slengths= csplength(p)
b=[slengths, p]
# path length select
for x in range(0,len(slengths)): # path length select
if sum(b[0][x])<self.options.len1: for x in range(0,len(slengths)):
l1.append(b[1][x]) if sum(b[0][x])<self.options.len1:
if self.options.len2>sum(b[0][x])>=self.options.len1 : l1.append(b[1][x])
l2.append(b[1][x]) if self.options.len2>sum(b[0][x])>=self.options.len1 :
if self.options.len3>sum(b[0][x])>=self.options.len2 : l2.append(b[1][x])
l3.append(b[1][x]) if self.options.len3>sum(b[0][x])>=self.options.len2 :
if self.options.len4>sum(b[0][x])>=self.options.len3 : l3.append(b[1][x])
l4.append(b[1][x]) if self.options.len4>sum(b[0][x])>=self.options.len3 :
if sum(b[0][x])>=self.options.len4 : l4.append(b[1][x])
l5.append(b[1][x]) if sum(b[0][x])>=self.options.len4 :
l5.append(b[1][x])
# make path
lensel=[l1,l2,l3,l4,l5] # make path
strlen=['#FF0001','#00FF02','#AAFF03','#87CEE4','#000FF5'] lensel=[l1,l2,l3,l4,l5]
for i,x in zip(strlen,lensel): strlen=['#FF0001','#00FF02','#AAFF03','#87CEE4','#000FF5']
s = {'stroke-linejoin': 'miter', 'stroke-width': '0.5px', for i,x in zip(strlen,lensel):
'stroke-opacity': '1.0', 'fill-opacity': '1.0', s = {'stroke-linejoin': 'miter', 'stroke-width': '0.5px',
'stroke': i, 'stroke-linecap': 'butt', 'fill': 'none'} 'stroke-opacity': '1.0', 'fill-opacity': '1.0',
attribs={'style':str(inkex.Style(s)),'d':str(paths.Path(paths.CubicSuperPath(x).to_path().to_arrays()))} 'stroke': i, 'stroke-linecap': 'butt', 'fill': 'none'}
etree.SubElement(node.getparent(),inkex.addNS('path','svg'),attribs) attribs={'style':str(inkex.Style(s)),'d':str(paths.Path(paths.CubicSuperPath(x).to_path().to_arrays()))}
etree.SubElement(node.getparent(),inkex.addNS('path','svg'),attribs)
if self.options.selection=="Path_slantselection": else:
for id, node in self.svg.selected.items(): self.msg('Please select some paths first.')
if node.tag == inkex.addNS('path','svg'): return
hor1,ver2,slan3=[],[],[]
p = paths.CubicSuperPath(inkex.paths.Path(node.get('d'))) if self.options.selection=="path_slantselection":
if len(self.svg.selected) > 0:
# path slant select for node in self.svg.selected.values():
for i,x in enumerate(p): if node.tag == inkex.addNS('path','svg'):
tn=roughBBox(x) hor1,ver2,slan3=[],[],[]
if tn<self.options.hor: p = paths.CubicSuperPath(inkex.paths.Path(node.get('d')))
hor1.append(p[i])
elif tn>self.options.ver: # path slant select
ver2.append(p[i]) for i,x in enumerate(p):
else: tn=roughBBox(x)
slan3.append(p[i]) if tn<self.options.hor:
hor1.append(p[i])
# make path elif tn>self.options.ver:
slnsel=[hor1,ver2,slan3] ver2.append(p[i])
strsln=['#FF0001','#00FF02','#000FF5'] else:
for i,x in zip(strsln,slnsel): slan3.append(p[i])
s = {'stroke-linejoin': 'miter', 'stroke-width': '0.5px',
'stroke-opacity': '1.0', 'fill-opacity': '1.0', # make path
'stroke': i, 'stroke-linecap': 'butt', 'fill': 'none'} slnsel=[hor1,ver2,slan3]
attribs={'style':str(inkex.Style(s)),'d':str(paths.Path(paths.CubicSuperPath(x).to_path().to_arrays()))} strsln=['#FF0001','#00FF02','#000FF5']
etree.SubElement(node.getparent(),inkex.addNS('path','svg'),attribs) for i,x in zip(strsln,slnsel):
s = {'stroke-linejoin': 'miter', 'stroke-width': '0.5px',
'stroke-opacity': '1.0', 'fill-opacity': '1.0',
'stroke': i, 'stroke-linecap': 'butt', 'fill': 'none'}
attribs={'style':str(inkex.Style(s)),'d':str(paths.Path(paths.CubicSuperPath(x).to_path().to_arrays()))}
etree.SubElement(node.getparent(),inkex.addNS('path','svg'),attribs)
else:
self.msg('Please select some paths first.')
return
if __name__ == '__main__': if __name__ == '__main__':
Length().run() Length().run()

View File

@ -23,7 +23,7 @@
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
# Please uncomment (remove the # character) in the following line to disable LaTeX support via textext extension. # Please uncomment (remove the # character) in the following line to disable LaTeX support via textext extension.
# useLatex=False useLatex=False
import os import os