Пример #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
Пример #2
0
def makeImg(images):
    gripper = Rectangle(295, 125, 120, 125)
    obstacles = [gripper]
    # grip = Image.new('RGB', (125,125), color=400)
    # white background
    clusterBack = Image.open("scripts/objects/back.png")
    # background of result
    background = Image.open("scripts/objects/" + backName + ".png")
    # radius for checking if objects are inside circle and positioning center
    radius = 180 # 180
    xCenter = 160
    yRadius = 210
    yCenter = 210
    # x from 0 to 310; y from 155 - sqrt(-(x-310)x) to 155 + sqrt(-(x-310)x)
    x = np.random.normal(xCenter, (radius*1.2))
    # print (radius/2), yRadius/2
    # field = Image.new('RGB', (int(radius*1.2),int(yRadius*1.2)), color=400)
    # yRadius = math.sqrt(-1 * x * (x - radius * 2))
    y = np.random.normal(yCenter, (yRadius*1.2))
    center = (x,y)
    order = []
    for i in range(1, 5):
        # selects objects in random order
        j = random.randrange(0, len(images))
        name = "scripts/objects/" + "obj" + str(images[j]) + ".png"
        order.append(images[j])
        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)
        foundLoc = (not z.hasCollision(obstacles) and z.insideRectangle((0, 2*yRadius), (2*radius,0)))
        if not foundLoc:
            # print "Failed: ", (x,y)
            return None, None, order
        else:
            pasteOn(clusterBack, obj, objX, objY)
        obstacles.append(z)
    # Random angle from -30 to 30; noise
    theta = (random.random() * 60) - 30
    clusterBack = clusterBack.rotate(theta)
    clusterBack = makeTransparent(clusterBack)
    # pasteOn(background, field, xCenter - int(radius/2*1.2), yCenter- int(yRadius/2*1.2))
    # pasteOn(background, field, 0, 0)
    pasteOn(background, clusterBack, 0, 0)
    return background, center, order
Пример #3
0
for k in range(0, numArrangements):
    images = [1, 2, 3, 4]
    obstacles = []
    background = Image.open("back.png")
    goal = Image.open("goal.png")
    # radius for positioning UL corner of goal
    radius = 155
    # radius for checking if objects are inside circle
    trueRadius = 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)
    gObj = Rectangle(x, goal.size[0], y, goal.size[1])
    obstacles.append(gObj)
    pasteOn(background, goal, x, y)
    # starting angle relative to goal
    theta = random.randrange(0, 360)
    # angle increment between objects
    thetaInc = 90
    # angle increment when placing one object
    thetaShift = 5
    for i in range(1, 5):
        # tracks length of current iteration
        currentTheta = 0
        # selects objects in random order
        j = random.randrange(0, len(images))
        name = "obj" + str(images[j]) + ".png"
        images.pop(j)
        obj = Image.open(name)
        # random small rotation of object