TXLWizard.Patterns.Polygon

Implements a class for Pattern objects of type Polygon (B).

Renders an polygon.

Classes

Polygon(Points, **kwargs) Implements a class for Pattern objects of type Polygon.
class TXLWizard.Patterns.Polygon.Polygon(Points, **kwargs)[source]

Bases: TXLWizard.Patterns.AbstractPattern.AbstractPattern

Implements a class for Pattern objects of type Polygon.

Corresponds to the TXL command B

Renders an polygon.

The boundary is always closed so the last point connects to the starting point

Parameters:
  • Points (list of list of float) – List of points (each point is a list of float, specifying the x- and y-coordinate of the point) that define the polygon
  • **kwargs – keyword arguments passed to the TXLWizard.Patterns.AbstractPattern.AbstractPattern constructor. Can specify attributes of the current pattern.

Examples

Import required modules

>>> import TXLWizard.TXLWriter

Initialize TXLWriter

>>> TXLWriter = TXLWizard.TXLWriter.TXLWriter()

Create Content Structure for polygon and add Pattern of type Polygon

>>> PolygonStructure = TXLWriter.AddContentStructure('MyPolygonID')
>>> PolygonStructure.AddPattern(
...     'Polygon',
...     Points=[[0,0], [0,10], [20,50], [0,0]],
...     Layer=1
... ) 
<TXLWizard.Patterns.Polygon.Polygon object at 0x...>

Complex structures can easily be added by generating the polygon points

>>> import math
>>> PolygonPoints = []
>>> Radius = 5.
>>> for i in range(21):
...     # AngleRadians goes from 0 to pi in 20 steps
...     AngleRadians = 0.5*2.*math.pi*1./20.*i
...     PolygonPoints.append([
...         Radius*math.cos(AngleRadians),Radius*math.sin(AngleRadians)
...     ])
>>> PolygonPoints.append([-20,-30])
>>> PolygonPoints.append([20,-30])
>>>
>>> PolygonStructure.AddPattern(
...     'Polygon',
...     Points=PolygonPoints,
...     Layer=1
... ) 
<TXLWizard.Patterns.Polygon.Polygon object at 0x...>

Generate Files

>>> TXLWriter.GenerateFiles('Tests/Results/Patterns/Polygon')
Points = None

list of list of float – List of points (each point is a list of float, specifying the x- and y-coordinate of the point) that define the polygon

Type = None

str – specifies the type of the pattern. Set to ‘Polygon’