.
This commit is contained in:
27
extensions/fablabchemnitz/flash_burst/flash_burst.inx
Normal file
27
extensions/fablabchemnitz/flash_burst/flash_burst.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">flash_burst.py</command>
|
||||
</script>
|
||||
</inkscape-extension>
|
105
extensions/fablabchemnitz/flash_burst/flash_burst.py
Normal file
105
extensions/fablabchemnitz/flash_burst/flash_burst.py
Normal 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()
|
||||
|
Reference in New Issue
Block a user