fix bug in fibonacci pattern
This commit is contained in:
parent
ef51a90dda
commit
34d058deb3
@ -40,27 +40,27 @@ def draw_SVG_ellipse(rx, ry, cx, cy, parent, start_end=(0,2*math.pi),transform='
|
|||||||
ell = etree.SubElement(parent, inkex.addNS('path','svg'), ell_attribs )
|
ell = etree.SubElement(parent, inkex.addNS('path','svg'), ell_attribs )
|
||||||
|
|
||||||
# This is the workhorse, it draws the circle based on which node number
|
# This is the workhorse, it draws the circle based on which node number
|
||||||
def drawKthCircle(k,firstRadius,lastRadius,numNodes,spreadFactor,parent):
|
def drawKthCircle(k,firstRadius, lastRadius, numNodes, spreadFactor, parent):
|
||||||
# Use golden circle phi
|
# Use golden circle phi
|
||||||
phi = (math.sqrt(5) - 1)/2
|
phi = (math.sqrt(5) - 1)/2
|
||||||
|
|
||||||
# Calculate the node radius
|
# Calculate the node radius
|
||||||
growth = lastRadius - firstRadius
|
growth = lastRadius - firstRadius
|
||||||
nodeRadius = firstRadius + growth*float(k - 1)/float(numNodes)
|
nodeRadius = firstRadius + growth * float(k - 1) / float(numNodes)
|
||||||
|
|
||||||
# Calculate X and Y from theta = 2 pi phi k and radius = sqrt(k)
|
# Calculate X and Y from theta = 2 pi phi k and radius = sqrt(k)
|
||||||
r = spreadFactor * math.sqrt(k)
|
r = spreadFactor * math.sqrt(k)
|
||||||
theta = 2*math.pi*phi*k
|
theta = 2 * math.pi * phi * k
|
||||||
|
|
||||||
# use simple trig to get cx and cy
|
# use simple trig to get cx and cy
|
||||||
x = r * math.cos(theta)
|
x = r * math.cos(theta)
|
||||||
y = r * math.sin(theta)
|
y = r * math.sin(theta)
|
||||||
|
|
||||||
# Add the px to the size
|
# Add the px to the size
|
||||||
nodeRadiusTxt = "%spx"%nodeRadius
|
nodeRadiusTxt = "%spx" % nodeRadius
|
||||||
|
|
||||||
# Draw the node
|
# Draw the node
|
||||||
draw_SVG_ellipse(nodeRadiusTxt,nodeRadiusTxt,x,y,parent)
|
draw_SVG_ellipse(nodeRadiusTxt, nodeRadiusTxt , x, y, parent)
|
||||||
|
|
||||||
|
|
||||||
class FibonacciPattern(inkex.EffectExtension):
|
class FibonacciPattern(inkex.EffectExtension):
|
||||||
@ -72,15 +72,15 @@ class FibonacciPattern(inkex.EffectExtension):
|
|||||||
pars.add_argument("-s", "--SpreadFactor",type=int, default="10", help="This will create a larger spread between the nodes from the center.")
|
pars.add_argument("-s", "--SpreadFactor",type=int, default="10", help="This will create a larger spread between the nodes from the center.")
|
||||||
|
|
||||||
def effect(self):
|
def effect(self):
|
||||||
# Foreach Node
|
|
||||||
|
group = self.document.getroot().add(inkex.Group(id="fibonacci-pattern-" + self.svg.get_unique_id("")))
|
||||||
for k in range(1,self.options.NumberOfNodes):
|
for k in range(1,self.options.NumberOfNodes):
|
||||||
# Draw the circle
|
|
||||||
drawKthCircle(k,
|
drawKthCircle(k,
|
||||||
self.options.FirstRadius,
|
self.options.FirstRadius,
|
||||||
self.options.LastRadius,
|
self.options.LastRadius,
|
||||||
self.options.NumberOfNodes,
|
self.options.NumberOfNodes,
|
||||||
self.options.SpreadFactor,
|
self.options.SpreadFactor,
|
||||||
self.svg.get_current_layer())
|
group)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
FibonacciPattern().run()
|
FibonacciPattern().run()
|
Loading…
Reference in New Issue
Block a user