def generate_case(self): node_lst = [] for i in range(50): circ = Circle(np.array([i, i]), 1) node_lst.append(circ) new_obj = Circle(np.array([10, 10]), 1) return [node_lst, new_obj]
def MakeCircle (): c = Circle(self.MouseX, self.MouseY, int(self.window.guiController.radius.get())) c.SetFill(self.window.guiController.fillColour['text']) c.SetOutlineColour(self.window.guiController.lineColour['text']) c.SetOutlineThickness(int(self.window.guiController.lineWidth.get())) self.window.objectController.addObject(c)
def createShape(type): if type.lower() == 'square': return Square() elif type.lower() == 'rectangle': return Rectangle() elif type.lower() == 'circle': return Circle() else: return None
def test_split_node(self): new_obj = self.generate_case()[1] node_lst = [] for i in range(5): circ = Circle(np.array([i, i]), 1) node_lst.append(circ) L = LeafNode(node_lst) [left_leaf, right_leaf] = RTree.split_node(L, new_obj) self.assertTrue(isinstance(left_leaf, LeafNode)) self.assertTrue(isinstance(right_leaf, LeafNode))
def getGraphics(self, plain, converter): wires = plain.findall("wire") polygons = plain.findall("polygon") texts = plain.findall("text") circles = plain.findall("circle") for wire in wires: self.plain.append(Line(wire, converter)) for polygon in polygons: self.plain.append(Polyline(polygon, converter)) for text in texts: self.plain.append(Text(text, converter)) for circle in circles: self.plain.append(Circle(circle, converter))
def DrawImage(polyList, imageX, imageY): im = Image.new('RGB', (imageX, imageY)) draw = ImageDraw.Draw(im, 'RGBA') for poly in polyList: poly.DrawOnImage(draw) return im allPoly = [] for x in range(nPoly): initCentre = [random.randint(0, imageX), random.randint(0, imageY)] initFill = random.randint(0, 255) initRadius = random.randint(0,255) initRGBA = [initFill, initFill, initFill, random.randint(0,255)] allPoly.append(Circle(initCentre, initRadius, initRGBA, imageX, imageY, nV)) fig = pyplot.figure() im = DrawImage(allPoly, imageX, imageY) prevFit = fitness(im) myobj = pyplot.imshow(im) def updateImg(i): global allPoly, prevFit mutatePoly = random.randint(0, nPoly-1) allPoly2 = copy.deepcopy(allPoly) allPoly2[mutatePoly].MediumMutate()
from Shapes import Square, Star, Circle, YumYum import time Star().run(6) Star().run(6) Star().run(6) Star().run(6) Circle().run() Square().run() Star().run()
E.father = None self.bounding_box = self.get_bounding_box() self.num -= 1 def get_bounding_box(self): if not self.children: return None else: bb_1 = self.children[0].bounding_box for item in self.children: bb_new = item.bounding_box bb_1 = bb_1.add_bb(bb_new) return bb_1 def get_order(self): order, L = 0, self while True: L = L.children[0] order += 1 if isinstance(L, LeafNode): break return order if __name__ == '__main__': circ_1 = Circle(np.array([1, 2]), 1) rtree = RTree(5) rtree.insert(circ_1) print(rtree.head.elem) leaf_1 = LeafNode([circ_1])
def test_shape_union(self): shape_1 = Circle(np.array([1, 1]), 1) shape_2 = Line(np.array([-2, -2]), np.array([-1, -1])) shape_union = ShapeUnion(shape_1, shape_2) self.assertEqual(shape_union.bounding_box, None)
def test_Circle(self): circ_bb = Circle(np.array([1, 1]), 1).bounding_box self.assertEqual(circ_bb.xlower, 0) self.assertEqual(circ_bb.yupper, 2)
def mousePressEvent(self, event): self.__clickx = event.x() self.__clicky = event.y() self.__randomLength = randint(10, 100) self.__randomWidth = randint(10, 100) triangle_orientation = randint(1, 4) colors = [Qt.magenta, Qt.blue, Qt.red, Qt.yellow, Qt.cyan, Qt.green] color_choice = colors[randint(0, 5)] shape_choice = randint(1, 7) if shape_choice == 1: newshape = Rectangle(self.__clickx - (self.__randomLength / 2), self.__clicky - (self.__randomWidth / 2), self.__randomLength, self.__randomWidth, color_choice) self.__shapes.append(newshape) if shape_choice == 2: newshape = Ellipse(self.__clickx - (self.__randomLength / 2), self.__clicky - (self.__randomWidth / 2), self.__randomLength, self.__randomWidth, color_choice) self.__shapes.append(newshape) if shape_choice == 3: newshape = Square(self.__clickx - (self.__randomLength / 2), self.__clicky - (self.__randomLength / 2), self.__randomLength, color_choice) self.__shapes.append(newshape) if shape_choice == 4: newshape = Circle(self.__clickx - (self.__randomLength / 2), self.__clicky - (self.__randomLength / 2), self.__randomLength, color_choice) self.__shapes.append(newshape) if shape_choice == 5: if triangle_orientation == 1: newshape = Triangle( (self.__clickx - (self.__randomLength / 2)), self.__clicky, self.__randomLength, color_choice, triangle_orientation) self.__shapes.append(newshape) if triangle_orientation == 2: newshape = Triangle( (self.__clickx + (self.__randomLength / 2)), self.__clicky, self.__randomLength, color_choice, triangle_orientation) self.__shapes.append(newshape) if triangle_orientation == 3: newshape = Triangle(self.__clickx, self.__clicky + (self.__randomLength / 2), self.__randomLength, color_choice, triangle_orientation) self.__shapes.append(newshape) if triangle_orientation == 4: newshape = Triangle(self.__clickx, self.__clicky - (self.__randomLength / 2), self.__randomLength, color_choice, triangle_orientation) self.__shapes.append(newshape) if shape_choice == 6: newshape = HourGlass(self.__clickx, self.__clicky + self.__randomLength, self.__randomLength, color_choice) self.__shapes.append(newshape) if shape_choice == 7: newshape = Diamond(self.__clickx, self.__clicky + self.__randomLength, self.__randomLength, color_choice) self.__shapes.append(newshape) self.update()
import matplotlib.pyplot as plt import numpy as np from Shapes import Point, Arc, Circle, Grid, Line, RotationMatrix plt.figure() plt.clf() pt0 = Point(0, 0) pt1 = Point(1, 1) pt2 = Point(2, 0) pt0.plot() pt1.plot() pt2.plot() arc = Arc(pt0, 1, 0, 2*np.pi) arc.plot(arrow='->') Line(pt0, pt1).plot(arrow='<->') Line(pt0, pt2).plot(arrow='->') circle = Circle(pt0, 2) circle.plot() plt.axis('equal') grid = Grid(pt0, pt1, 5) #grid.plot(color='k', lw=1) plt.show()
# Two points p1 = Point(0, 0) print(p1) print(repr(p1)) print() p2 = Point(10, 10) print(p2) print(repr(p2)) # In[91]: # Two circles c1 = Circle(0, 0, 10) print(c1) print(repr(c1)) print() c2 = Circle(-4, 2, 8) print(c2) print(repr(c2)) # In[88]: # Two triangles t1 = Triangle(0, 0, 6, 8, 10) print(t1) print(repr(t1))
from time import sleep import threading from Shapes import Square, Star, Circle, YumYum DEVICE_NAME = 'prototype' MAX_ITERATIONS = 10 FOOD = "FOOD" SHAPE = "SHAPE" OFFER = "OFFER" ANSWER = "ANSWER" shapes = {"SQUARE":Square(), "STAR": Star(), "CIRCLE": Circle(), } # Use a service account cred = credentials.Certificate('firestore-sdk.json') firebase_admin.initialize_app(cred) db = firestore.client() doc_ref = db.collection('users').document(DEVICE_NAME) # Create an Event for notifying main thread. callback_done = threading.Event() def message_handler(message_type, message, play_time):
import numpy as np from Shapes import Rectangle, Circle, Line, Point, BoundingBox, ShapeUnion from RTree import RTree, Node, LeafNode node_lst = [] for i in range(500): circ = Circle(np.array([i, i]), 1, id={'name': 'node' + str(i)}) node_lst.append(circ) #for item in node_lst: # print(item.id['name']+':') # item.bounding_box.print() import random random.seed(42) r_tree = RTree(M=3) i = 1 for item in node_lst: r_tree.insert(item) head = r_tree.head print('\n') head.bounding_box.print() for c in head.children: c.bounding_box.print() print('\nlayer 1: ', c) if isinstance(c, LeafNode): for k in c.elem: print(k.id['name']) else: for e in c.children:
def generateEffects(e, e1): speedUp = Circle((e, e1), GREEN, 7) speedDown = Polygon((e, e1), RED, 14) return rn.choice([speedUp, speedDown])