예제 #1
0
 def _placeInfoElements(self, button, box):
     button.angle = math.pi/4
     box.angle = math.pi/4
     
     angle =   -math.pi/4
     baseDisplacement = math.sqrt(2*(self.size[0]**2)) /2.0
     infoButtonElementAdjustemnt = util.getVectotInDirection(angle ,
                                                         -baseDisplacement + math.sqrt(2*(button.size[1]**2))/2)
     infoBoxElementAdjustemnt = util.getVectotInDirection(angle,
                                                         baseDisplacement + box.size[1]/2)
  
     util.centerNodeOnPosition(button, infoButtonElementAdjustemnt)
     util.centerNodeOnPosition(box, infoBoxElementAdjustemnt)
예제 #2
0
    def checkForSpace(self, element):
        radius = element.shape.radius + util.CRYSTAL_RADIUS + 1
        availablePositions = []
        stepsize = 360 // 4
        maxNeigbors = 0
        for alpha in range(0, 360, stepsize):
            alpha += random.randint(0, stepsize - 1)
            # alpha+= random.randrange(stepsize)
            angle = (2 * math.pi) * (alpha / 360.0)
            vector = util.getVectotInDirection(angle, radius)
            posToCheck = util.vectorAdd(self.toAbsPos(element.position), vector)
            testBody = pymunk.Body()
            testBody.position = posToCheck
            shapeToTestInner = pymunk.Circle(body=testBody, radius=util.CRYSTAL_SIZE / 2)
            shapeToTestOuter = pymunk.Circle(
                body=testBody, radius=(util.CRYSTAL_SIZE / 2) * self.neighbourhoodThreshold
            )
            intersectionsInner = self._space.shape_query(shapeToTestInner)
            # dnode = avg.CircleNode(parent=self._root.getParent(), pos=posToCheck, r=util.CRYSTAL_SIZE/2,fillcolor="00FFFF", strokewidth=0)
            if len(intersectionsInner) == 0 or (len(intersectionsInner) == 1 and element.shape in intersectionsInner):
                intersectionsOuter = self._space.shape_query(shapeToTestOuter)
                neighborCount = len(intersectionsOuter)
                # dnode.fillopacity=0.5
                if neighborCount > maxNeigbors:
                    maxNeigbors = neighborCount
                    availablePositions = [self.toRelPos(posToCheck)]
                elif neighborCount == maxNeigbors:
                    availablePositions.append(self.toRelPos(posToCheck))

        return availablePositions
예제 #3
0
    def _placeInfoElements(self, button, box):
        angle =  math.pi/2
        baseDisplacement = math.sqrt(2*(self.size[0]**2)) /2.0
        infoBoxElementAdjustemnt = util.getVectotInDirection(angle,
                                                            -baseDisplacement - box.size[1]/2)
     
        buttonPos =  (-self.size[0]*0.23, self.size[1]*0.27)
        button.size = util.vectorMult(self.size, 0.20) 
        util.centerNodeOnPosition(button, buttonPos)
        util.centerNodeOnPosition(box, infoBoxElementAdjustemnt)

        util.centerNodeOnPosition(box, infoBoxElementAdjustemnt)