added starshine and flashburst extension; fixed path2openscad tracemalloc warnings
This commit is contained in:
parent
873c52130d
commit
cf0cd160d1
27
extensions/fablabchemnitz/flashburst.inx
Normal file
27
extensions/fablabchemnitz/flashburst.inx
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||
<name>Flash Burst</name>
|
||||
<id>fablabchemnitz.de.flash_burst</id>
|
||||
<param name="r1" type="int" min="1" max="20" gui-text="Radius - inner (min)">10</param>
|
||||
<param name="r2" type="int" min="1" max="20" gui-text="Radius - inner (max)">10</param>
|
||||
<separator/>
|
||||
<param name="R1" type="int" min="200" max="500" gui-text="Radius - outer (min)">350</param>
|
||||
<param name="R2" type="int" min="200" max="500" gui-text="Radius - outer (max)">350</param>
|
||||
<separator/>
|
||||
<param name="a1" type="int" min="1" max="45" gui-text="Angle (min)">5</param>
|
||||
<param name="a2" type="int" min="1" max="45" gui-text="Angle (max)">10</param>
|
||||
<separator/>
|
||||
<param name="ad1" type="int" min="1" max="10" gui-text="Angle delta (min)">3</param>
|
||||
<param name="ad2" type="int" min="1" max="10" gui-text="Angle delta (max)">5</param>
|
||||
<effect>
|
||||
<object-type>all</object-type>
|
||||
<effects-menu>
|
||||
<submenu name="FabLab Chemnitz">
|
||||
<submenu name="Shape/Pattern from Generator"/>
|
||||
</submenu>
|
||||
</effects-menu>
|
||||
</effect>
|
||||
<script>
|
||||
<command location="inx" interpreter="python">flashburst.py</command>
|
||||
</script>
|
||||
</inkscape-extension>
|
105
extensions/fablabchemnitz/flashburst.py
Executable file
105
extensions/fablabchemnitz/flashburst.py
Executable file
@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (C) 2021 Stefan Benediktsson
|
||||
#
|
||||
# GNU Affero General Public License v3.0
|
||||
# Permissions of this strongest copyleft license are
|
||||
# conditioned on making available complete source code
|
||||
# of licensed works and modifications, which include
|
||||
# larger works using a licensed work, under the same
|
||||
# license. Copyright and license notices must be preserved.
|
||||
# Contributors provide an express grant of patent rights.
|
||||
# When a modified version is used to provide a service
|
||||
# over a network, the complete source code of the modified
|
||||
# version must be made available.
|
||||
"""
|
||||
Generate a FlashBurst as SVG.
|
||||
"""
|
||||
|
||||
import random
|
||||
from math import acos, cos, radians, sin, sqrt, tan
|
||||
|
||||
import inkex
|
||||
|
||||
|
||||
def points_to_svgd(p):
|
||||
"""
|
||||
p: list of 2 tuples (x, y coordinates)
|
||||
"""
|
||||
f = p[0]
|
||||
p = p[1:]
|
||||
svgd = 'M{:.3f},{:.3f}'.format(f[0], f[1])
|
||||
for x in p:
|
||||
svgd += 'L{:.3f},{:.3f}'.format(x[0], x[1])
|
||||
svgd +='Z'
|
||||
return svgd
|
||||
|
||||
def checkSize(a, b):
|
||||
if a >= b:
|
||||
return b, a
|
||||
else:
|
||||
return a, b
|
||||
|
||||
class FlashBurst(inkex.GenerateExtension):
|
||||
container_label = 'Rendered FlashBurst'
|
||||
def add_arguments(self, pars):
|
||||
|
||||
pars.add_argument("--r1", type=int, default=20, help="Inner Radius min")
|
||||
pars.add_argument("--r2", type=int, default=20, help="Inner Radius max")
|
||||
pars.add_argument("--R1", type=int, default=350, help="Outer Radius min")
|
||||
pars.add_argument("--R2", type=int, default=350, help="Outer Radius min")
|
||||
pars.add_argument("--a1", type=int, default=5, help="Angle min")
|
||||
pars.add_argument("--a2", type=int, default=7, help="Angle max")
|
||||
pars.add_argument("--ad1", type=int, default=3, help="Angle delta min")
|
||||
pars.add_argument("--ad2", type=int, default=2, help="Angle delta max")
|
||||
|
||||
|
||||
|
||||
def generate(self):
|
||||
r1 = self.options.r1
|
||||
r2 = self.options.r2
|
||||
R1 = self.options.R1
|
||||
R2 = self.options.R2
|
||||
a1 = self.options.a1
|
||||
a2 = self.options.a2
|
||||
ad1 = self.options.ad1
|
||||
ad2 = self.options.ad2
|
||||
|
||||
# generate points: list of (x, y) pairs
|
||||
|
||||
r1, r2 = checkSize(r1, r2)
|
||||
R1, R2 = checkSize(R1, R2)
|
||||
a1, a2 = checkSize(a1, a2)
|
||||
ad1, ad2 = checkSize(ad1, ad2)
|
||||
|
||||
a = 0
|
||||
oX = 0
|
||||
oY = 0
|
||||
style = {'stroke': '#000000', 'fill': '#000000', 'stroke-width': str(self.svg.unittouu('1px'))}
|
||||
|
||||
while a < 360:
|
||||
a = a+random.randint(a1,a2)
|
||||
dI = random.randint(r1,r2)
|
||||
dO = random.randint(R1,R2)
|
||||
ad = random.randint(ad1,ad2)
|
||||
|
||||
x0 = cos(radians(a)) * dI
|
||||
y0 = sin(radians(a)) * dI
|
||||
|
||||
x10 = cos(radians(a-ad/2)) * dO
|
||||
y10 = sin(radians(a-ad/2)) * dO
|
||||
|
||||
x11 = cos(radians(a+ad/2)) * dO
|
||||
y11 = sin(radians(a+ad/2)) * dO
|
||||
|
||||
points = []
|
||||
points.append((x0, y0))
|
||||
points.append((x10,y10))
|
||||
points.append((x11,y11))
|
||||
path = points_to_svgd(points)
|
||||
|
||||
yield inkex.PathElement(style=str(inkex.Style(style)), d=str(path))
|
||||
|
||||
if __name__ == '__main__':
|
||||
FlashBurst().run()
|
||||
|
@ -26,7 +26,7 @@
|
||||
<param name="smoothness" type="float" min="0.0001" max="5" precision="4" gui-text="Smoothing">0.2</param>
|
||||
<label>Used when rendering curves. Smaller values are smoother. Range: 0.0001 to 5</label>
|
||||
<param type="float" name="chamfer" min="0.0" gui-text="Add chamfer radius [mm]">0</param>
|
||||
<param name="chamfer_fn" type="optiongroup" appearance="combo" gui-text="Chamfer präzision ($fn)">
|
||||
<param name="chamfer_fn" type="optiongroup" appearance="combo" gui-text="Chamfer precision ($fn)">
|
||||
<option value="4">4: Rough (fast)</option>
|
||||
<option value="12">12: Medium (slow)</option>
|
||||
<option value="16">16: Fine (slower)</option>
|
||||
|
@ -418,31 +418,30 @@ def msg_extrude_by_hull_and_paths(id, prefix):
|
||||
return msg
|
||||
|
||||
|
||||
class OpenSCAD(inkex.Effect):
|
||||
def __init__(self):
|
||||
class OpenSCAD(inkex.EffectExtension):
|
||||
|
||||
def add_arguments(self, pars):
|
||||
inkex.localization.localize() # does not help for localizing my *.inx file
|
||||
inkex.Effect.__init__(self)
|
||||
|
||||
self.arg_parser.add_argument( "--tab", default="splash", help="The active tab when Apply was pressed", )
|
||||
self.arg_parser.add_argument( "--smoothness", type=float, default=float(0.2), help="Curve smoothing (less for more)", )
|
||||
self.arg_parser.add_argument( "--chamfer", type=float, default=float(1.), help="Add a chamfer radius, displacing all object walls outwards [mm]", )
|
||||
self.arg_parser.add_argument( "--chamfer_fn", type=int, default=int(4), help="Chamfer precision ($fn when generating the minkowski sphere)", )
|
||||
self.arg_parser.add_argument( "--zsize", default="5", help="Depth (Z-size) [mm]", )
|
||||
self.arg_parser.add_argument( "--min_line_width", type=float, default=float(1), help="Line width for non closed curves [mm]", )
|
||||
self.arg_parser.add_argument( "--line_width_scale_perc", type=float, default=float(1), help="Percentage of SVG line width. Use e.g. 26.46 to compensate a px/mm confusion. Default: 100 [%]", )
|
||||
self.arg_parser.add_argument( "--line_fn", type=int, default=int(4), help="Line width precision ($fn when constructing hull)", )
|
||||
self.arg_parser.add_argument( "--force_line", type=inkex.utils.Boolean, default=False, help="Force outline mode.", )
|
||||
self.arg_parser.add_argument( "--fname", default="{NAME}.scad", help="openSCAD output file derived from the svg file name.", )
|
||||
self.arg_parser.add_argument( "--parsedesc", default="true", help="Parse zsize and other parameters from object descriptions", )
|
||||
self.arg_parser.add_argument( "--scadview", default="false", help="Open the file with openscad ( details see --scadviewcmd option )", )
|
||||
self.arg_parser.add_argument( "--scadviewcmd", default=INX_SCADVIEW, help="Command used start an openscad viewer. Use {SCAD} for the openSCAD input.", )
|
||||
self.arg_parser.add_argument( "--scad2stl", default="false", help="Also convert to STL ( details see --scad2stlcmd option )", )
|
||||
self.arg_parser.add_argument( "--scad2stlcmd", default=INX_SCAD2STL, help="Command used to convert to STL. You can use {NAME}.scad for the openSCAD file to read and "
|
||||
pars.add_argument( "--tab", default="splash", help="The active tab when Apply was pressed", )
|
||||
pars.add_argument( "--smoothness", type=float, default=float(0.2), help="Curve smoothing (less for more)", )
|
||||
pars.add_argument( "--chamfer", type=float, default=float(1.), help="Add a chamfer radius, displacing all object walls outwards [mm]", )
|
||||
pars.add_argument( "--chamfer_fn", type=int, default=int(4), help="Chamfer precision ($fn when generating the minkowski sphere)", )
|
||||
pars.add_argument( "--zsize", default="5", help="Depth (Z-size) [mm]", )
|
||||
pars.add_argument( "--min_line_width", type=float, default=float(1), help="Line width for non closed curves [mm]", )
|
||||
pars.add_argument( "--line_width_scale_perc", type=float, default=float(1), help="Percentage of SVG line width. Use e.g. 26.46 to compensate a px/mm confusion. Default: 100 [%]", )
|
||||
pars.add_argument( "--line_fn", type=int, default=int(4), help="Line width precision ($fn when constructing hull)", )
|
||||
pars.add_argument( "--force_line", type=inkex.utils.Boolean, default=False, help="Force outline mode.", )
|
||||
pars.add_argument( "--fname", default="{NAME}.scad", help="openSCAD output file derived from the svg file name.", )
|
||||
pars.add_argument( "--parsedesc", default="true", help="Parse zsize and other parameters from object descriptions", )
|
||||
pars.add_argument( "--scadview", default="false", help="Open the file with openscad ( details see --scadviewcmd option )", )
|
||||
pars.add_argument( "--scadviewcmd", default=INX_SCADVIEW, help="Command used start an openscad viewer. Use {SCAD} for the openSCAD input.", )
|
||||
pars.add_argument( "--scad2stl", default="false", help="Also convert to STL ( details see --scad2stlcmd option )", )
|
||||
pars.add_argument( "--scad2stlcmd", default=INX_SCAD2STL, help="Command used to convert to STL. You can use {NAME}.scad for the openSCAD file to read and "
|
||||
+ "{NAME}.stl for the STL file to write.", )
|
||||
self.arg_parser.add_argument( "--stlpost", default="false", help="Start e.g. a slicer. This implies the --scad2stl option. ( see --stlpostcmd )", )
|
||||
self.arg_parser.add_argument( "--stlpostcmd", default=INX_STL_POSTPROCESSING, help="Command used for post processing an STL file (typically a slicer). You can use {NAME}.stl for the STL file.", )
|
||||
self.arg_parser.add_argument( "--stlmodule",default="false", help="Output configured to comment out final rendering line, to create a module file for import.", )
|
||||
pars.add_argument( "--stlpost", default="false", help="Start e.g. a slicer. This implies the --scad2stl option. ( see --stlpostcmd )", )
|
||||
pars.add_argument( "--stlpostcmd", default=INX_STL_POSTPROCESSING, help="Command used for post processing an STL file (typically a slicer). You can use {NAME}.stl for the STL file.", )
|
||||
pars.add_argument( "--stlmodule",default="false", help="Output configured to comment out final rendering line, to create a module file for import.", )
|
||||
|
||||
self.userunitsx = 1.0 # Move to pure userunits per mm for v1.0
|
||||
self.userunitsy = 1.0
|
||||
@ -1396,9 +1395,9 @@ module chamfer_sphere(rad=chamfer, res=chamfer_fn)
|
||||
except Exception:
|
||||
tty = subprocess.PIPE
|
||||
try:
|
||||
proc = subprocess.Popen(
|
||||
cmd, shell=True, stdin=tty, stdout=tty, stderr=tty
|
||||
)
|
||||
proc = subprocess.Popen(cmd, shell=True, stdin=tty, stdout=tty, stderr=tty)
|
||||
proc.wait()
|
||||
tty.close()
|
||||
except OSError as e:
|
||||
raise OSError("%s failed: errno=%d %s" % (cmd, e.errno, e.strerror))
|
||||
try:
|
||||
@ -1428,13 +1427,8 @@ module chamfer_sphere(rad=chamfer, res=chamfer_fn)
|
||||
import subprocess
|
||||
|
||||
try:
|
||||
proc = subprocess.Popen(
|
||||
cmd,
|
||||
shell=True,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
proc.wait()
|
||||
except OSError as e:
|
||||
raise OSError(
|
||||
"{0} failed: errno={1} {2}".format(cmd, e.errno, e.strerror)
|
||||
@ -1459,8 +1453,7 @@ module chamfer_sphere(rad=chamfer, res=chamfer_fn)
|
||||
inkex.errormsg("= " * 24)
|
||||
if len <= 0: # something is wrong. better stop here
|
||||
self.options.stlpost = "false"
|
||||
stdout.close()
|
||||
stderr.close()
|
||||
proc.wait()
|
||||
if self.options.stlpost == "true":
|
||||
cmd = self.options.stlpostcmd.format(
|
||||
**{"STL": self.basename + ".stl", "NAME": self.basename}
|
||||
@ -1471,9 +1464,8 @@ module chamfer_sphere(rad=chamfer, res=chamfer_fn)
|
||||
tty = subprocess.PIPE
|
||||
|
||||
try:
|
||||
proc = subprocess.Popen(
|
||||
cmd, shell=True, stdin=tty, stdout=tty, stderr=tty
|
||||
)
|
||||
proc = subprocess.Popen(cmd, shell=True, stdin=tty, stdout=tty, stderr=tty)
|
||||
proc.wait()
|
||||
except OSError as e:
|
||||
raise OSError("%s failed: errno=%d %s" % (cmd, e.errno, e.strerror))
|
||||
|
||||
@ -1487,8 +1479,6 @@ module chamfer_sphere(rad=chamfer, res=chamfer_fn)
|
||||
if stderr:
|
||||
inkex.errmsg("STDERR: {}".format(stderr))
|
||||
inkex.errormsg("= " * 24)
|
||||
stdout.close()
|
||||
stderr.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
OpenSCAD().run()
|
24
extensions/fablabchemnitz/starshine.inx
Normal file
24
extensions/fablabchemnitz/starshine.inx
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||
<name>Starshine</name>
|
||||
<id>fablabchemnitz.de.starshine</id>
|
||||
<param name="r1" type="int" min="1" max="50" gui-text="Radius - inner (min)">10</param>
|
||||
<param name="r2" type="int" min="1" max="50" gui-text="Radius - inner (max)">10</param>
|
||||
<separator/>
|
||||
<param name="R1" type="int" min="100" max="500" gui-text="Radius - outer (min)">350</param>
|
||||
<param name="R2" type="int" min="100" max="500" gui-text="Radius - outer (max)">350</param>
|
||||
<separator/>
|
||||
<param name="a1" type="int" min="1" max="20" gui-text="Angle (min)">4</param>
|
||||
<param name="a2" type="int" min="1" max="20" gui-text="Angle (max)">10</param>
|
||||
<effect>
|
||||
<object-type>all</object-type>
|
||||
<effects-menu>
|
||||
<submenu name="FabLab Chemnitz">
|
||||
<submenu name="Shape/Pattern from Generator"/>
|
||||
</submenu>
|
||||
</effects-menu>
|
||||
</effect>
|
||||
<script>
|
||||
<command location="inx" interpreter="python">starshine.py</command>
|
||||
</script>
|
||||
</inkscape-extension>
|
105
extensions/fablabchemnitz/starshine.py
Executable file
105
extensions/fablabchemnitz/starshine.py
Executable file
@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (C) 2021 Stefan Benediktsson
|
||||
#
|
||||
# GNU Affero General Public License v3.0
|
||||
# Permissions of this strongest copyleft license are
|
||||
# conditioned on making available complete source code
|
||||
# of licensed works and modifications, which include
|
||||
# larger works using a licensed work, under the same
|
||||
# license. Copyright and license notices must be preserved.
|
||||
# Contributors provide an express grant of patent rights.
|
||||
# When a modified version is used to provide a service
|
||||
# over a network, the complete source code of the modified
|
||||
# version must be made available.
|
||||
#
|
||||
"""
|
||||
Generate a Starshine as SVG.
|
||||
"""
|
||||
|
||||
import random
|
||||
from math import acos, cos, radians, sin, sqrt, tan
|
||||
|
||||
import inkex
|
||||
|
||||
|
||||
|
||||
def points_to_svgd(p):
|
||||
"""
|
||||
p: list of 2 tuples (x, y coordinates)
|
||||
"""
|
||||
f = p[0]
|
||||
p = p[1:]
|
||||
svgd = 'M{:.3f},{:.3f}'.format(f[0], f[1])
|
||||
for x in p:
|
||||
svgd += 'L{:.3f},{:.3f}'.format(x[0], x[1])
|
||||
svgd +='Z'
|
||||
return svgd
|
||||
|
||||
def checkSize(a, b):
|
||||
if a >= b:
|
||||
return b, a
|
||||
else:
|
||||
return a, b
|
||||
|
||||
class Starshine(inkex.GenerateExtension):
|
||||
container_label = 'Rendered Starshine'
|
||||
def add_arguments(self, pars):
|
||||
|
||||
pars.add_argument("--r1", type=int, default=20, help="Inner Radius min")
|
||||
pars.add_argument("--r2", type=int, default=20, help="Inner Radius max")
|
||||
pars.add_argument("--R1", type=int, default=350, help="Outer Radius min")
|
||||
pars.add_argument("--R2", type=int, default=350, help="Outer Radius min")
|
||||
pars.add_argument("--a1", type=int, default=5, help="Angle min")
|
||||
pars.add_argument("--a2", type=int, default=7, help="Angle max")
|
||||
|
||||
|
||||
|
||||
def generate(self):
|
||||
r1 = self.options.r1
|
||||
r2 = self.options.r2
|
||||
R1 = self.options.R1
|
||||
R2 = self.options.R2
|
||||
a1 = self.options.a1
|
||||
a2 = self.options.a2
|
||||
|
||||
|
||||
# generate points: list of (x, y) pairs
|
||||
|
||||
r1, r2 = checkSize(r1, r2)
|
||||
R1, R2 = checkSize(R1, R2)
|
||||
a1, a2 = checkSize(a1, a2)
|
||||
a = 0
|
||||
|
||||
style = {'stroke': '#000000', 'fill': '#000000', 'stroke-width': str(self.svg.unittouu('1px'))}
|
||||
|
||||
points = []
|
||||
|
||||
while a < 360:
|
||||
dI = random.randint(r1,r2)
|
||||
dO = random.randint(R1,R2)
|
||||
ad = random.randint(a1,a2)
|
||||
|
||||
x00 = cos(radians(a)) * dI
|
||||
y00 = sin(radians(a)) * dI
|
||||
|
||||
x10 = cos(radians(a+ad/2)) * dO
|
||||
y10 = sin(radians(a+ad/2)) * dO
|
||||
|
||||
x01 = cos(radians(a+ad)) * dI
|
||||
y01 = sin(radians(a+ad)) * dI
|
||||
|
||||
points.append((x00, y00))
|
||||
points.append((x10, y10))
|
||||
points.append((x01, y01))
|
||||
|
||||
a = a+ad
|
||||
|
||||
path = points_to_svgd(points)
|
||||
|
||||
yield inkex.PathElement(style=str(inkex.Style(style)), d=str(path))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
Starshine().run()
|
||||
|
Reference in New Issue
Block a user