core.components.fusion module

class core.components.fusion.Body[source]

Bases: object

A class that holds sprite, _color, and face position data for use with fusing two sprites together.

Param:None

Example:

>>> bulbasaur = Body()
>>> bulbasaur.load('fusion/Bulbasaur.json') # Load the sprite data from a json file
>>>
>>> gyarados = Body()
>>> gyarados.load('fusion/Gyarados.json')   # Load the sprite data from a json file
>>>
>>> # Fuse the sprites.
>>> fuse(body=bulbasaur, face=gyarados)
>>> fuse(body=gyarados, face=bulbasaur)
get_face_size()[source]

Obtains the size of the face image in pixels and sets the instance’s face_size to the returned value.

Param:None
Return type:Tuple
Returns:A tuple (x, y) of the face size in pixels.
load(json_data, file=True)[source]

Loads and sets all of the properties of this instance to the properties contained within a json string or file.

Parameters:
  • json_data (String) – The string of json text or the file path to a json file to load.
  • file (Boolean) – True or false value of whether or not “json_data” is a file path.
Return type:

None

Returns:

None

Example:

>>> bulbasaur = Body()
>>> bulbasaur.load('fusion/Bulbasaur.json')
save(filename=None)[source]

Saves the current instance and all its properties to a file containing json text.

Parameters:filename (String) – The path to the file to save.
Return type:None
Returns:None
to_json()[source]

Converts the current instance to a dictionary and converts it to json format.

Param:None
Return type:String
Returns:A json string of the current instance.
core.components.fusion.fuse(body, face, save=True, filename=None)[source]

Fuses two sprites together given a body and a face. The resulting body will take on the colors of the face.

Parameters:
  • body (fusion.Body) – A Body() instance of the body that will be used in the end result.
  • face (fusion.Body) – A Body() instance of the face that will be used in the end result.
  • save (Boolean) – True or false value of whether or not to save the resulting fusion to a file.
  • filename (String) – If saving the result, specify the filename to save the resulting image.
Return type:

PIL.Image

Returns:

A PIL Image() object of the fused sprites.

Example:

>>> bulbasaur = Body()
>>> bulbasaur.load('fusion/Bulbasaur.json')
>>>
>>> gyarados = Body()
>>> gyarados.load('fusion/Gyarados.json')
>>>
>>> # Fuse the sprites.
>>> fuse(body=bulbasaur, face=gyarados)
>>> fuse(body=gyarados, face=bulbasaur)
core.components.fusion.replace_color(image, original_color, replacement_color)[source]

Replaces an RGB _color in an image with a different RGB _color.

Parameters:
  • image (PIL.Image) – A PIL Image() object of the image to replace colors.
  • original_color (Tuple) – A tuple of the RGB (r, g, b) value of the _color to replace.
  • replacement_color (Tuple) – A tuple of the RGB (r, g, b) value of the new _color.
Return type:

PIL.Image

Returns:

A PIL Image() object of the image with the given colors replaced.