Esempio n. 1
0
    def setUp(self):
        self.C0 = circles.Circle()
        self.C0prim = circles.Circle()
        self.C112 = circles.Circle(1, 1, 2)

        self.p00 = Points.Point(0, 0)
        self.p11 = Points.Point(1, 1)
Esempio n. 2
0
 def test_cover(self):
     self.assertEqual(
         circles.Circle(0, 0, 2).cover(circles.Circle(0.5, 0.5, 1)),
         circles.Circle(0, 0, 2))
     self.assertEqual(
         circles.Circle(1, 1, 2).cover(circles.Circle(4, 5, 1)),
         circles.Circle(2.2, 2.6, 4.0))
Esempio n. 3
0
    def match(self, obj):
        for t in self.types:
            if isinstance(obj, t):
                return True
        return False


def inspect_attributes(obj, type_match=lambda obj: True):
    regex = re.compile(r'^(?!__).*$(?!__)')  # get rid of private stuff
    attributes = \
        [(x, getattr(obj, x)) for x in dir(obj) if regex.match(x)]
    return dict([x for x in attributes if type_match(x[1])])


if __name__ == '__main__':
    circle = circles.Circle(circles.Point(0, 1), 15)

    print(inspect_attributes(circle))

    point_matcher = TypeMatcher(circles.Point)
    print(inspect_attributes(circle, point_matcher.match))

    int_matcher = TypeMatcher(int)
    print(inspect_attributes(circle, int_matcher.match))

    t_class = type('TestType', (), {})
    t = t_class()
    t.att1 = 'Foo'
    t.att2 = circles.Point(0, 1)
    t.att3 = 12
    t.att4 = 12.3
Esempio n. 4
0
    def test_points_radius(self):  # test punktow i promienia
        self.assertEqual(self.C0.pt, self.p00)
        self.assertEqual(self.C0.radius, 1)

        with self.assertRaises(ValueError):
            circles.Circle(1, 1, -1)
Esempio n. 5
0
fpsClock = pygame.time.Clock()
fps = 100
SCREEN_WIDTH = 500
SCREEN_HEIGHT = 500

window = pygame.display.set_mode((SCREEN_HEIGHT, SCREEN_HEIGHT))
pygame.display.set_caption("pygame test")

whiteColor = pygame.Color(255, 255, 255)
blackColor = pygame.Color(0, 0, 0)
redColor = pygame.Color(255, 0, 0)

font = pygame.font.SysFont("monospace", 20)

# circle_ls = [Circle.Vector(187, 382, 46), Circle.Vector(490, 196, 30), Circle.Vector(224, 0, 25), Circle.Vector(438, 270, 47), Circle.Vector(197, 263, 40), Circle.Vector(76, 394, 45), Circle.Vector(499, 451, 49), Circle.Vector(203, 98, 35), Circle.Vector(111, 12, 32), Circle.Vector(37, 483, 40), Circle.Vector(377, 412, 29), Circle.Vector(278, 303, 44), Circle.Vector(298, 411, 39), Circle.Vector(21, 286, 38), Circle.Vector(66, 199, 27), Circle.Vector(16, 116, 49), Circle.Vector(446, 73, 37), Circle.Vector(91, 275, 30), Circle.Vector(491, 346, 27), Circle.Vector(321, 23, 27)]
circle = Circle.Circle(None)
circle_ls = circle.generate_random_circle(20, 40, 10, SCREEN_WIDTH,
                                          SCREEN_HEIGHT)
Circle.Circle.static_circle_list = circle_ls
circle = Circle.Circle(SCREEN_WIDTH, SCREEN_HEIGHT)
for _ in range(circle.POPULATION):
    chromo = (circle.generate_chromo(circle.CHROMO_SIZE))
    circle.population_ls.append(chromo)
    circle.population_fitness.append(circle.get_fitness_score(chromo))
    # print circle.population_dict
    # circle.population_avg.append(
    #     circle.population_fitness_avg(circle.population_dict))
gen_count = 0

while True:
    gen_count += 1
Esempio n. 6
0
# coding: utf8
import rectangles
import triangles
import circles

square2 = rectangles.Square(2)

print(square2.summary())

square2.draw()

triangle1 = triangles.Triangle(3, 3, 3)

print(triangle1.summary())

triangle1.draw()

circle1 = circles.Circle(5)

print(circle1.summary())

circle1.draw()
Esempio n. 7
0
import circles
import matplotlib.pyplot as plt

C1 = circles.Circle(1, 5, 2)
C2 = circles.Circle(1, 1, 1)

C3 = C1.cover(C2)
print C3

circle1 = plt.Circle((C1.pt.x, C1.pt.y), C1.radius, color='g', fill=False)
circle2 = plt.Circle((C2.pt.x, C2.pt.y), C2.radius, color='b', fill=False)
circle3 = plt.Circle((C3.pt.x, C3.pt.y), C3.radius, color='r', fill=False)

fig, ax = plt.subplots()  # note we must use plt.subplots, not plt.subplot
# (or if you have an existing figure)
# fig = plt.gcf()
# ax = fig.gca()

ax.add_artist(circle1)
ax.add_artist(circle2)
ax.add_artist(circle3)

ax.set_xlim(-3, 8)
ax.set_ylim(-3, 8)

plt.show()