zufall2
von detix- SNIPPET_TEXT:
-
- #! /usr/bin/python
- import inkex
- import simplestyle, sys
- from math import *
- from simplestyle import *
- from random import uniform
- class Zufallspunkte_im_Kreis(inkex.Effect):
- def __init__(self):
- inkex.Effect.__init__(self)
- self.OptionParser.add_option("--x",
- action="store", type="int",
- dest="x", default=0.0,
- help="Zentrum X")
- self.OptionParser.add_option("--y",
- action="store", type="int",
- dest="y", default=0.0,
- help="Zentrum Y")
- self.OptionParser.add_option("--radius",
- action="store", type="int",
- dest="radius", default=1000,
- help="Radius")
- self.OptionParser.add_option("--punkte",
- action="store", type="int",
- dest="punkte", default=100,
- help="Punkte")
- self.OptionParser.add_option("--punktgroesse",
- action="store", type="float",
- dest="punktgroesse", default=1,
- help="Punktgroesse")
- def draw_circle(self, radius, parent):
- style = { 'stroke' : '#000000',
- 'stroke-width' : '0.1',
- 'fill' : 'none' }
- ell_attribs = {'style':simplestyle.formatStyle(style),
- inkex.addNS('cx','sodipodi') :str(self.options.x),
- inkex.addNS('cy','sodipodi') :str(self.options.y),
- inkex.addNS('rx','sodipodi') :str(radius),
- inkex.addNS('ry','sodipodi') :str(radius),
- inkex.addNS('type','sodipodi') :'arc'
- }
- ell = inkex.etree.SubElement(parent, inkex.addNS('path','svg'), ell_attribs )
- def draw_points(self, x, y, radius, parent):
- style = { 'stroke' : 'none',
- 'stroke-width' : str(radius),
- 'fill' : '#ff0000' }
- ell_attribs = {'style':simplestyle.formatStyle(style),
- inkex.addNS('cx','sodipodi') :str(x),
- inkex.addNS('cy','sodipodi') :str(y),
- inkex.addNS('rx','sodipodi') :str(radius),
- inkex.addNS('ry','sodipodi') :str(radius),
- inkex.addNS('type','sodipodi') :'arc'
- }
- ell = inkex.etree.SubElement(parent, inkex.addNS('path','svg'), ell_attribs )
- def effect(self):
- parent = self.current_layer
- radius = self.unittouu(str(self.options.radius))
- self.x_offset = self.unittouu(str(self.options.x))
- self.y_offset = self.unittouu(str(self.options.y))
- self.draw_circle(self.options.radius, parent)
- for i in range(1,self.options.punkte + 1):
- x = uniform(-1, 1)
- y = uniform(-1, 1)
- if sqrt(x*x+y*y) <= 1:
- x1 = x * radius * 96 / 25.4 + self.options.x
- y1 = y * radius * 96 / 25.4 + self.options.y
- self.draw_points(x1, y1, str(self.options.punktgroesse/100.0), parent)
- if __name__ == '__main__':
- e = Zufallspunkte_im_Kreis()
- e.affect()
Quellcode
Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN