def assemble(self,roboset=None,color=None,format=None,bgset=None,sizex=300,sizey=300):
        """
        Build our Robot!
        Returns the robot image itself.
        """

        # Allow users to manually specify a robot 'set' that they like.
        # Ensure that this is one of the allowed choices, or allow all
        # If they don't set one, take the first entry from sets above.

        if roboset == 'any':
            roboset = self.sets[self.hasharray[1] % len(self.sets) ]
        elif roboset in self.sets:
            roboset = roboset
        else:
            roboset = self.sets[0]


        # Only set1 is setup to be color-seletable. The others don't have enough pieces in various colors.
        # This could/should probably be expanded at some point..
        # Right now, this feature is almost never used. ( It was < 44 requests this year, out of 78M reqs )

        if roboset == 'set1':
            if color in self.colors:
                roboset = 'set1/' + color
            else:
                randomcolor = self.colors[self.hasharray[0] % len(self.colors) ]
                roboset = 'set1/' + randomcolor

        # If they specified a background, ensure it's legal, then give it to them.
        if bgset in self.bgsets:
            bgset = bgset
        elif bgset == 'any':
            bgset = self.bgsets[ self.hasharray[2] % len(self.bgsets) ]

        # If we set a format based on extension earlier, use that. Otherwise, PNG.
        if format is None:
            format = self.format

        # Each directory in our set represents one piece of the Robot, such as the eyes, nose, mouth, etc.

        # Each directory is named with two numbers - The number before the # is the sort order.
        # This ensures that they always go in the same order when choosing pieces, regardless of OS.

        # The second number is the order in which to apply the pieces.
        # For instance, the head has to go down BEFORE the eyes, or the eyes would be hidden.

        # First, we'll get a list of parts of our robot.


        roboparts = self._get_list_of_files(self.resourcedir + 'sets/' + roboset)
        # Now that we've sorted them by the first number, we need to sort each sub-category by the second.
        roboparts.sort(key=lambda x: x.split("#")[1])
        if bgset is not None:
                bglist = []
                backgrounds = natsort.natsorted(os.listdir(self.resourcedir + 'backgrounds/' + bgset))
                backgrounds.sort()
                for ls in backgrounds:
                        if not ls.startswith("."):
                                bglist.append(self.resourcedir + 'backgrounds/' + bgset + "/" + ls)
                background = bglist[self.hasharray[3] % len(bglist)]

        # Paste in each piece of the Robot.
        roboimg = Image.open(roboparts[0])
        roboimg = roboimg.resize((1024,1024))
        for png in roboparts:
                img = Image.open(png)
                img = img.resize((1024,1024))
                roboimg.paste(img,(0,0),img)

        # If we're a BMP, flatten the image.
        if format == 'bmp':
                #Flatten bmps
                r, g, b, a = roboimg.split()
                roboimg = Image.merge("RGB", (r, g, b))

        if bgset is not None:
                bg = Image.open(background)
                bg = bg.resize((1024,1024))
                bg.paste(roboimg,(0,0),roboimg)
                roboimg = bg

        self.img = roboimg.resize((sizex,sizey),Image.ANTIALIAS)
        self.format = format
def assemble ( self , roboset = None , color = None , format = None , bgset = None , sizex = 300 , sizey = 300 ) : if roboset == 'any' : roboset = self . sets [ self . hasharray [ 1 ] % len ( self . sets ) ] elif roboset in self . sets : roboset = roboset else : roboset = self . sets [ 0 ] if roboset == 'set1' : if color in self . colors : roboset = 'set1/' + color else : randomcolor = self . colors [ self . hasharray [ 0 ] % len ( self . colors ) ] roboset = 'set1/' + randomcolor if bgset in self . bgsets : bgset = bgset elif bgset == 'any' : bgset = self . bgsets [ self . hasharray [ 2 ] % len ( self . bgsets ) ] if format is None : format = self . format roboparts = self . _get_list_of_files ( self . resourcedir + 'sets/' + roboset ) roboparts . sort ( key = lambda x : x . split ( "#" ) [ 1 ] ) if bgset is not None : bglist = [ ] backgrounds = natsort . natsorted ( os . listdir ( self . resourcedir + 'backgrounds/' + bgset ) ) backgrounds . sort ( ) for ls in backgrounds : if not ls . startswith ( "." ) : bglist . append ( self . resourcedir + 'backgrounds/' + bgset + "/" + ls ) background = bglist [ self . hasharray [ 3 ] % len ( bglist ) ] roboimg = Image . open ( roboparts [ 0 ] ) roboimg = roboimg . resize ( ( 1024 , 1024 ) ) for png in roboparts : img = Image . open ( png ) img = img . resize ( ( 1024 , 1024 ) ) roboimg . paste ( img , ( 0 , 0 ) , img ) if format == 'bmp' : r , g , b , a = roboimg . split ( ) roboimg = Image . merge ( "RGB" , ( r , g , b ) ) if bgset is not None : bg = Image . open ( background ) bg = bg . resize ( ( 1024 , 1024 ) ) bg . paste ( roboimg , ( 0 , 0 ) , roboimg ) roboimg = bg self . img = roboimg . resize ( ( sizex , sizey ) , Image . ANTIALIAS ) self . format = format
Build our Robot!
        Returns the robot image itself.