tuxemon.fusion module
- class tuxemon.fusion.Body[source]
Bases:
object
A class that holds data for use with fusing two sprites together.
Example
Two Tuxemon can be fused by joining the face of one with the body of another.
>>> sapsnap = Body() >>> # Load the sprite data from a json file >>> sapsnap.load('fusion/Sapsnap.json') >>> >>> vivitron = Body() >>> # Load the sprite data from a json file >>> vivitron.load('fusion/Vivitron.json') >>> >>> # Fuse the sprites. >>> fuse(body=sapsnap, face=vivitron) >>> fuse(body=vivitron, face=sapsnap)
- body_image: Image
- face_image: Image
- get_face_size()[source]
Obtains the size of the face image in pixels.
It also sets the instance’s face_size to the returned value.
- Returns:
A tuple (x, y) of the face size in pixels.
- Return type:
Tuple[int, int]
- load(json_data, file=True)[source]
Loads and sets all the properties to the properties in a json.
- Parameters:
json_data (str) – The string of json text or the file path to a json file to load.
file (bool) – True or false value of whether or not “json_data” is a file path.
- Return type:
None
Example
>>> sapsnap = Body() >>> sapsnap.load('fusion/Sapsnap.json')
- tuxemon.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 (Body) – A Body() instance of the body that will be used in the end result.
face (Body) – A Body() instance of the face that will be used in the end result.
save (bool) – True or false value of whether or not to save the resulting fusion to a file.
filename (Optional[str]) – If saving the result, specify the filename to save the resulting image.
- Returns:
A PIL Image() object of the fused sprites.
- Return type:
Image
Example
>>> sapsnap = Body() >>> sapsnap.load('fusion/Sapsnap.json') >>> >>> vivitron = Body() >>> vivitron.load('fusion/Vivitron.json') >>> >>> # Fuse the sprites. >>> fuse(body=sapsnap, face=vivitron) >>> fuse(body=vivitron, face=sapsnap)
- tuxemon.fusion.replace_color(image, original_color, replacement_color)[source]
Replaces an RGB color in an image with a different RGB _color.
- Parameters:
image (Image) – A PIL Image() object of the image to replace colors.
original_color (Tuple[int, int, int]) – A tuple of the RGB (r, g, b) value of the color to replace.
replacement_color (Tuple[int, int, int]) – A tuple of the RGB (r, g, b) value of the new color.
- Returns:
A PIL Image() object of the image with the given colors replaced.
- Return type:
Image