2023-10-30 21:51:28 +00:00
|
|
|
import drawsvg as draw
|
|
|
|
import math
|
|
|
|
import random
|
|
|
|
|
|
|
|
|
2023-11-01 12:26:38 +00:00
|
|
|
class Circle:
|
|
|
|
def __init__(self, length=1000, height=1000, radius=10, distance=60, offset=30):
|
|
|
|
# run validations
|
|
|
|
assert length >= 0, "length can not be negative"
|
|
|
|
assert radius >= 0, "radius can not be negative"
|
|
|
|
assert distance >= 2*radius, "distance must be grater den two times the radius"
|
|
|
|
|
|
|
|
# Assign to self object
|
|
|
|
self.__length = length
|
|
|
|
self.__height = height
|
|
|
|
self.__radius = radius
|
|
|
|
self.__distance = distance
|
|
|
|
self.__offset = offset
|
|
|
|
|
|
|
|
def circle_generation(self):
|
|
|
|
|
|
|
|
x1 = 10
|
|
|
|
y1 = 10
|
|
|
|
y = y1
|
|
|
|
v = 1
|
|
|
|
g = 1
|
|
|
|
|
|
|
|
canvas = draw.Drawing(self.__length, self.__height, origin=(0, 0))
|
|
|
|
|
|
|
|
while y <= self.__height:
|
|
|
|
x = x1 + self.__offset * v
|
|
|
|
while x <= self.__length:
|
|
|
|
canvas.append(draw.Circle(x, y, self.__radius,
|
|
|
|
fill='none', stroke_width=1, stroke='black'))
|
|
|
|
x = x + self.__distance
|
|
|
|
y = y + self.__distance
|
|
|
|
v = -((1 - g) / 2)
|
|
|
|
g = -g
|
|
|
|
|
|
|
|
canvas.save_svg('example.svg')
|
2023-10-30 21:51:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2023-11-01 12:26:38 +00:00
|
|
|
circle = Circle()
|
|
|
|
circle.circle_generation()
|
|
|
|
|