#main_script
import fme
import fmeobjects
import random
import numpy as np
from fmeobjects import FMELine, FMEGeometryTools
from math import sqrt, cos, sin, pi
width = 360
N = 8
d=width/N
def translate(points,x_diff, y_diff):
# input list of lists
# with coordinates [[x0,y0][x1,y1][x2,y2]]
# add diff values for each x and y
translated_coords = [[i[0] + x_diff, i[1] + y_diff]
for i in points
]
return translated_coords
def pattern(x, y, size):
l = size / sqrt(4)
points = []
for i in range(4):
r = 3 * pi / 3 * i + pi / 6
points.append([l * cos(r), l * sin(r)])
for i in range(4):
r = 3 * pi / 3 * i + pi / 6 + pi
points.append([l * cos(r), l * sin(r)])
#move the current position to the given x and y values.
x_start, y_start = x, y + l / 2
translated_points = translate(points,x_start, y_start)
points = translated_points
return points
class FeatureProcessor(object):
def __init__(self):
pass
def input(self, feature: fmeobjects.FMEFeature):
# svg_body = create_svg_no_deps(datastructure,'foo')
pass
def close(self):
for i in range(2 * N + 1):
x = d * i / 2
dy = d * sqrt(3) / 2 if i % 2 == 1 else 0
for j in range(N):
y = d * j * sqrt(3)
points = pattern(x, y + dy, d)
pts_crd = [(i[0],i[1]) for i in points[0:2]]
linefeature = fmeobjects.FMEFeature()
line = FMELine(pts_crd) # init(points) (list[tuple[float]]) The list of points to set to the line. The points are represented as (x, y) or (x, y, z) tuples
linefeature.setGeometry(line)
self.pyoutput(linefeature)