From f29e72e3ae7a4fcd23dc070808fe75258b808512 Mon Sep 17 00:00:00 2001 From: Mika Date: Wed, 1 Nov 2023 13:26:38 +0100 Subject: [PATCH] Klasse Circle mit Methode circle_generation fertig gestellt --- mustergenerator.py | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/mustergenerator.py b/mustergenerator.py index f125d6c..7d62b84 100644 --- a/mustergenerator.py +++ b/mustergenerator.py @@ -3,10 +3,44 @@ import math import random -class Hexagon: - def __int__(self): - pass +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') if __name__ == '__main__': - x = 1 + circle = Circle() + circle.circle_generation() +