Exemplo n.º 1
0
def makeImg(images):
    obstacles = []
    background = Image.open("back.png")
    # radius for checking if objects are inside circle and positioning center
    radius = 180
    # x from 0 to 310; y from 155 - sqrt(-(x-310)x) to 155 + sqrt(-(x-310)x)
    x = np.random.normal(radius, (radius/goalVariance)/3)
    yRadius = math.sqrt(-1 * x * (x - radius * 2))
    y = np.random.normal(radius, (yRadius)/3)
    for i in range(1, 5):
        # selects objects in random order
        j = random.randrange(0, len(images))
        name = "obj" + str(images[j]) + ".png"
        images.pop(j)
        obj = Image.open(name)
        objX = x
        objY = y
        # splits objects into four quadrants around point
        if (i % 2 == 0):
            objX -= w(obj)
        if (i > 2):
            objY -= h(obj)
        z = Rectangle(objX, w(obj), objY, h(obj))
        foundLoc = (not z.hasCollision(obstacles)) and z.insideCircle(radius, radius, radius)
        if not foundLoc:
            return None
        else:
            pasteOn(background, obj, objX, objY)
        obstacles.append(z)
    return background
Exemplo n.º 2
0
         if (reRotate):
             rotLimit += 20
             rObj = obj.rotate(getRot(rotLimit), Image.NEAREST, True)
             reRotate = False
         # avoid infinite loops
         if (rotLimit > 700):
             foundLoc = True
         hasSpace = True
         radialD = w(goal)/2
         # iterates distance from goal to find valid placement at current angle
         while (not foundLoc and hasSpace):
             objx = gObj.cenX + radialD * cosine(theta)
             objy = gObj.cenY + radialD * sine(theta)
             z = Rectangle(objx, w(rObj), objy, h(rObj))
             foundLoc = not z.hasCollision(obstacles)
             hasSpace = z.insideCircle(trueRadius, trueRadius, trueRadius)
             foundLoc = foundLoc and hasSpace
             radialD += 5
             if (foundLoc):
                 pasteOn(background, rObj, objx, objy)
                 obstacles.append(z)
             # change angle if no valid placement is available at current angle
             elif (not hasSpace):
                 currentTheta += thetaShift
                 theta += thetaShift
             # changes object rotation if no valid placement is available at any angle
             if (currentTheta > 720):
                 currentTheta = 0
                 reRotate = True
     theta += thetaInc
 # save arrangements as numbered png files