fix bug in chip_scratches, add randomize option

This commit is contained in:
Mario Voigt 2023-10-14 14:46:18 +02:00
parent 3e31fbfc4f
commit c14423b6f5
2 changed files with 63 additions and 51 deletions

View File

@ -14,6 +14,7 @@
<separator/> <separator/>
<param name="mainSize" type="float" max="100.0" precision="3" gui-text="Size of objects (scale factor)">1.000</param> <param name="mainSize" type="float" max="100.0" precision="3" gui-text="Size of objects (scale factor)">1.000</param>
<param name="mainNum" type="int" max="5000" gui-text="Number of objects (acts as multiplicator)">1</param> <param name="mainNum" type="int" max="5000" gui-text="Number of objects (acts as multiplicator)">1</param>
<param name="randomize" type="bool" gui-text="Randomize number of objects">true</param>
<param name="allInOneGroup" type="bool" gui-text="Put all items into one group">true</param> <param name="allInOneGroup" type="bool" gui-text="Put all items into one group">true</param>
</page> </page>
<page name="Scratches" gui-text="Scratches"> <page name="Scratches" gui-text="Scratches">

View File

@ -107,6 +107,7 @@ for number and size, as well as some specific to each type.
pars.add_argument("--sgrow", type= float, default=0.0, help="Grow specks with distance") pars.add_argument("--sgrow", type= float, default=0.0, help="Grow specks with distance")
pars.add_argument("--snum", type= int, default=10, help="Number of specks") pars.add_argument("--snum", type= int, default=10, help="Number of specks")
pars.add_argument("--sgrad", type=inkex.Boolean, default=False, help="Use density gradient") pars.add_argument("--sgrad", type=inkex.Boolean, default=False, help="Use density gradient")
pars.add_argument("--randomize", type=inkex.Boolean, default=False, help="Randomize number of objects")
pars.add_argument("--Nmain", "--Overall") pars.add_argument("--Nmain", "--Overall")
def effect(self): def effect(self):
@ -142,6 +143,7 @@ for number and size, as well as some specific to each type.
'ang' : self.options.hang, 'ang' : self.options.hang,
'curve' : self.options.hcurve, 'curve' : self.options.hcurve,
'grad' : self.options.hgrad, 'grad' : self.options.hgrad,
'randomize': self.options.randomize,
} }
pdic_chips = { pdic_chips = {
'x' : x, 'x' : x,
@ -156,6 +158,7 @@ for number and size, as well as some specific to each type.
'ang' : False, 'ang' : False,
'curve' : False, 'curve' : False,
'grad' : self.options.cgrad, 'grad' : self.options.cgrad,
'randomize': self.options.randomize,
} }
pdic_specks = { pdic_specks = {
'x' : x, 'x' : x,
@ -170,6 +173,7 @@ for number and size, as well as some specific to each type.
'ang' : False, 'ang' : False,
'curve' : False, 'curve' : False,
'grad' : self.options.sgrad, 'grad' : self.options.sgrad,
'randomize': self.options.randomize,
} }
uniqId = self.svg.get_unique_id('chipscratches-') uniqId = self.svg.get_unique_id('chipscratches-')
scId =self.svg.get_unique_id('') scId =self.svg.get_unique_id('')
@ -182,55 +186,59 @@ for number and size, as well as some specific to each type.
inkex.utils.debug("No rectangle(s) have been selected.") inkex.utils.debug("No rectangle(s) have been selected.")
exit(1) exit(1)
pdic_scratches = { if aiog is False: #otherwise we have a lot of duplicates!
'x' : x, pdic_scratches = {
'y' : y, 'x' : x,
'rx' : rx, 'y' : y,
'ry' : ry, 'rx' : rx,
'size' : self.options.mainSize * self.options.hsize, 'ry' : ry,
'enable' : self.options.honp, 'size' : self.options.mainSize * self.options.hsize,
'num' : self.options.mainNum * self.options.hnum, 'enable' : self.options.honp,
'grow' : self.options.hgrow, 'num' : self.options.mainNum * self.options.hnum,
'radial' : self.options.hrad, 'grow' : self.options.hgrow,
'ang' : self.options.hang, 'radial' : self.options.hrad,
'curve' : self.options.hcurve, 'ang' : self.options.hang,
'grad' : self.options.hgrad, 'curve' : self.options.hcurve,
} 'grad' : self.options.hgrad,
pdic_chips = { 'randomize': self.options.randomize,
'x' : x, }
'y' : y, pdic_chips = {
'rx' : rx, 'x' : x,
'ry' : ry, 'y' : y,
'size' : self.options.mainSize * self.options.csize, 'rx' : rx,
'enable' : self.options.conp, 'ry' : ry,
'num' : self.options.mainNum * self.options.cnum, 'size' : self.options.mainSize * self.options.csize,
'grow' : self.options.cgrow, 'enable' : self.options.conp,
'radial' : False, 'num' : self.options.mainNum * self.options.cnum,
'ang' : False, 'grow' : self.options.cgrow,
'curve' : False, 'radial' : False,
'grad' : self.options.cgrad, 'ang' : False,
} 'curve' : False,
pdic_specks = { 'grad' : self.options.cgrad,
'x' : x, 'randomize': self.options.randomize,
'y' : y, }
'rx' : rx, pdic_specks = {
'ry' : ry, 'x' : x,
'size' : self.options.mainSize * self.options.ssize, 'y' : y,
'enable' : self.options.sonp, 'rx' : rx,
'num' : self.options.mainNum * self.options.snum, 'ry' : ry,
'grow' : self.options.sgrow, 'size' : self.options.mainSize * self.options.ssize,
'radial' : False, 'enable' : self.options.sonp,
'ang' : False, 'num' : self.options.mainNum * self.options.snum,
'curve' : False, 'grow' : self.options.sgrow,
'grad' : self.options.sgrad, 'radial' : False,
} 'ang' : False,
uniqId = self.svg.get_unique_id('chipscratches-') 'curve' : False,
scId =self.svg.get_unique_id('') 'grad' : self.options.sgrad,
if aiog is True: 'randomize': self.options.randomize,
group = parent.add(inkex.Group(id=uniqId)) }
draw(group if aiog is True else parent.add(inkex.Group(id='scratches-' + scId)), scratches, pdic_scratches) uniqId = self.svg.get_unique_id('chipscratches-')
draw(group if aiog is True else parent.add(inkex.Group(id='chips-' + scId)), chips, pdic_chips) scId =self.svg.get_unique_id('')
draw(group if aiog is True else parent.add(inkex.Group(id='specks-' + scId)), specks, pdic_specks) if aiog is True:
group = parent.add(inkex.Group(id=uniqId))
draw(group if aiog is True else parent.add(inkex.Group(id='scratches-' + scId)), scratches, pdic_scratches)
draw(group if aiog is True else parent.add(inkex.Group(id='chips-' + scId)), chips, pdic_chips)
draw(group if aiog is True else parent.add(inkex.Group(id='specks-' + scId)), specks, pdic_specks)
def createDict(): def createDict():
return return
@ -253,11 +261,14 @@ def draw(group, obj, pdic) :
mrmax = mrx if mrx > mry else mry mrmax = mrx if mrx > mry else mry
#Curves 90 going from the center to the edge (long dim.) if parm = 1.0 #Curves 90 going from the center to the edge (long dim.) if parm = 1.0
curve = pdic['curve'] * 0.5 * math.pi / mrmax curve = pdic['curve'] * 0.5 * math.pi / mrmax
if pdic['randomize'] is True:
cnt = (random.randint(0, int(pdic['num'])))
else:
cnt = pdic['num']
ctrs = [( ctrs = [(
x + rx * f(random.random()) , x + rx * f(random.random()) ,
y + ry * f(random.random()) y + ry * f(random.random())
) for i in range(pdic['num'])] ) for i in range(cnt)]
zp = 2 + 3 * int(random.random()*len(obj) / 3 ) zp = 2 + 3 * int(random.random()*len(obj) / 3 )
for ctr in ctrs : for ctr in ctrs :
path = etree.Element(inkex.addNS('path','svg')) path = etree.Element(inkex.addNS('path','svg'))