svgwrite rotate issues causes spiral result

44 Views Asked by At

Im trying to create canvas filed with triangles with random rotation and size but as soon as I try rotation everything gets out of wack. If rotation is turned off the resulting svg looks like expected

enter image description here

As soon as I try to get triangles to be rotated it all spirals out of control.

enter image description here

    def create_triangle(size, rotation, color):
      triangle = svgwrite.shapes.Polygon(points=[
        (0, size), (size / 2, 0), (size, size),], fill=color)
      triangle.rotate(rotation, center=(size / 2, size / 2))
      return triangle
    
dwg = svgwrite.Drawing(size=(canvas_width, canvas_height), profile='tiny')
        
y = 0
x = 0
i = 0
        
for y in range(0, canvas_height, distance):
 i += 1
 rotation = random.uniform(0, rotation_range)
 random_size = random.uniform(min_size, size)
 tri = create_triangle(random_size, i, colors[i*2])
 tri.translate(x, y)
 dwg.add(tri)
        
 dwg.save()
0

There are 0 best solutions below