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>
<id>fablabchemnitz.de.pathselection</id>
<param name="selection" type="optiongroup" appearance="combo" gui-text="Selection: ">
<option value="Path_lengthselection">Length_selection</option>
<option value="Path_slantselection">Slant_selection</option>
<option value="path_lengthselection">Length selection</option>
<option value="path_slantselection">Slant selection</option>
</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="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="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="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>
<object-type>path</object-type>
<effects-menu>

View File

@ -69,62 +69,70 @@ class Length(inkex.EffectExtension):
def effect(self):
# loop over all selected paths
if self.options.selection=="Path_lengthselection":
for id, node in self.svg.selected.items():
if node.tag == inkex.addNS('path','svg'):
l1,l2,l3,l4,l5=[],[],[],[],[]
p = paths.CubicSuperPath(inkex.paths.Path(node.get('d')))
slengths= csplength(p)
b=[slengths, p]
if self.options.selection=="path_lengthselection":
if len(self.svg.selected) > 0:
for node in self.svg.selected.values():
if node.tag == inkex.addNS('path','svg'):
l1,l2,l3,l4,l5=[],[],[],[],[]
p = paths.CubicSuperPath(inkex.paths.Path(node.get('d')))
slengths= csplength(p)
b=[slengths, p]
# path length select
for x in range(0,len(slengths)):
if sum(b[0][x])<self.options.len1:
l1.append(b[1][x])
if self.options.len2>sum(b[0][x])>=self.options.len1 :
l2.append(b[1][x])
if self.options.len3>sum(b[0][x])>=self.options.len2 :
l3.append(b[1][x])
if self.options.len4>sum(b[0][x])>=self.options.len3 :
l4.append(b[1][x])
if sum(b[0][x])>=self.options.len4 :
l5.append(b[1][x])
# path length select
for x in range(0,len(slengths)):
if sum(b[0][x])<self.options.len1:
l1.append(b[1][x])
if self.options.len2>sum(b[0][x])>=self.options.len1 :
l2.append(b[1][x])
if self.options.len3>sum(b[0][x])>=self.options.len2 :
l3.append(b[1][x])
if self.options.len4>sum(b[0][x])>=self.options.len3 :
l4.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]
strlen=['#FF0001','#00FF02','#AAFF03','#87CEE4','#000FF5']
for i,x in zip(strlen,lensel):
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)
# make path
lensel=[l1,l2,l3,l4,l5]
strlen=['#FF0001','#00FF02','#AAFF03','#87CEE4','#000FF5']
for i,x in zip(strlen,lensel):
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 self.options.selection=="Path_slantselection":
for id, node in self.svg.selected.items():
if node.tag == inkex.addNS('path','svg'):
hor1,ver2,slan3=[],[],[]
p = paths.CubicSuperPath(inkex.paths.Path(node.get('d')))
if self.options.selection=="path_slantselection":
if len(self.svg.selected) > 0:
for node in self.svg.selected.values():
if node.tag == inkex.addNS('path','svg'):
hor1,ver2,slan3=[],[],[]
p = paths.CubicSuperPath(inkex.paths.Path(node.get('d')))
# path slant select
for i,x in enumerate(p):
tn=roughBBox(x)
if tn<self.options.hor:
hor1.append(p[i])
elif tn>self.options.ver:
ver2.append(p[i])
else:
slan3.append(p[i])
# path slant select
for i,x in enumerate(p):
tn=roughBBox(x)
if tn<self.options.hor:
hor1.append(p[i])
elif tn>self.options.ver:
ver2.append(p[i])
else:
slan3.append(p[i])
# make path
slnsel=[hor1,ver2,slan3]
strsln=['#FF0001','#00FF02','#000FF5']
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)
# make path
slnsel=[hor1,ver2,slan3]
strsln=['#FF0001','#00FF02','#000FF5']
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__':
Length().run()

View File

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