Appearance -> Background#

The ‘Background’ class is a child classes of the ‘Appearance’ class.

classDiagram Appearance <|-- Costume Appearance <|-- Background Token o-- Appearance class Token{ +add_costume() } class Appearance{ +add_image(str) } class Costume{ } class Background{ }

Note

Usually backgrounds are created with board.add_background([image_path|color])

Background#

class miniworldmaker.appearances.background.Background(*args, **kwargs)[source]#

The class describes the background of a board.

A background can be an image or a color:

Each board has one or more backgrounds that can be switched between. In addition, each background also has several pictures (or colors) between which you can switch.

Examples

Add an image as background

board = Board()
Board.add_background(images/my_image.png)

Add a color as background:

board = Board()
Board.add_background((255, 0,0, 0))

..or alternative way: Create background with property:

from miniworldmaker import *

board = Board()
board.background =(255,0,0)
board.run()

Public Data Attributes:

board

Implemented in subclasses Costume and Background

grid

Shows a grid-overlay

image_manager

Inherited from Appearance

counter

RELOAD_ACTUAL_IMAGE

LOAD_NEW_IMAGE

font_size

animation_speed

is_textured

If True, the image is tiled over the background.

is_rotatable

If True, costume will be rotated with token direction

is_centered

orientation

If True, the image will be rotated by parent orientation before it is rotated.

is_flipped

Flips the costume or background.

is_scaled

Scales the actor to parent-size without remaining aspect-ratio.

is_upscaled

If True, the image will be upscaled remaining aspect-ratio.

is_scaled_to_width

is_scaled_to_height

fill_color

coloring

Defines a colored layer.

transparency

Defines a transparency.

alpha

transparent, 255: visible If value < 1, it will be multiplied with 255.

is_animated

If True, the costume will be animated.

color

->See fill color

is_filled

Is token filled with color?

stroke_color

see border color

border_color

border color of token

border

The border-size of token.

text

Sets text of appearance .

images

image

Performs all actions in image pipeline

dirty

board

Implemented in subclasses Costume and Background

image_manager

Public Methods:

__init__([board])

set_dirty([value, status])

show_grid()

repaint()

Called 1/frame from board

add_image(source)

Adds an image to the appearance

Inherited from Appearance

__init__()

set_defaults(rotatable, is_animated, ...)

rtype:

Appearance

after_init()

set_font(font, font_size)

set_animation_speed(value)

flip(value)

get_text_width()

get_text_height()

remove_last_image()

add_image(source)

Adds an image to the appearance

set_image(source)

Sets the displayed image of costume/background to selected index

add_images(sources)

Adds multiple images to background/costume.

animate([loop])

Animates the costume

after_animation()

the method is overwritten in subclasses costume and appearance

to_colors_array()

Create an array from costume or background.

from_array(arr)

Create a background or costume from array.

fill(value)

Set default fill color for borders and lines

get_color(position)

get_rect()

draw(source, position, width, height)

draw_on_image(path, position, width, height)

draw_color_on_image(color, position, width, ...)

__str__()

Return str(self).

set_text(value)

get_image()

If dirty, the image will be reloaded.

update()

Loads the next image, called 1/frame

register(method)

Register method for decorator.

draw_shape_append(shape, arguments)

draw_shape_set(shape, arguments)

draw_image_append(surface, rect)

draw_image_set(surface, rect)

set_dirty([value, status])

Private Data Attributes:

_abc_impl

Inherited from Appearance

_abc_impl

Private Methods:

_update_all_costumes()

updates costumes for all tokens on board

_after_transformation_pipeline()

Called in get_image, if image is "dirty" (e.g.

_blit_to_window_surface()

Blits background to window surface

_inner_shape()

Returns inner shape of costume

_outer_shape()

Returns outer shape of costume

Inherited from Appearance

_before_transformation_pipeline()

Called in get_image, if image is "dirty" (e.g.

_after_transformation_pipeline()

Called in get_image, if image is "dirty" (e.g.

_load_image()

Loads the image,

_update_draw_shape()

rtype:

None

_inner_shape()

Returns inner shape of costume

_outer_shape()

Returns outer shape of costume

_inner_shape_arguments()

def setGets arguments for inner shape

_outer_shape_arguments()

Gets arguments for outer shape


add_image(source)[source]#

Adds an image to the appearance

Return type:

int

Returns:

Index of the created image.

property board: Board#

Implemented in subclasses Costume and Background

property grid: bool | tuple#

Shows a grid-overlay

grid can be True, False or a color-tuple

Examples

Show grid:

from miniworldmaker import *

board = TiledBoard(4,4)
board.tile_margin = 10
background = board.add_background("images/stone.png")
background.is_textured = True
token = Token()
@token.register
def on_key_down(self, key):
    self.move_right()
background.grid = True
board.run()
Textured image
parent#

The parent of a Background is the associated board.

repaint()[source]#

Called 1/frame from board

set_dirty(value='all', status=1)[source]#
show_grid()[source]#