Token: Shapes

Shape

Base class for shapes

class miniworldmaker.tokens.shapes.Shape(position=None, color=(255, 255, 255, 255))[source]

Base class for Shapes

classmethod from_center(position, color)[source]

Creates a token with center at center_position

Parameters

center_position – Center of token

Point

class miniworldmaker.tokens.shapes.Point(position=None, thickness=1, color=(255, 255, 255, 255))[source]

A Point-Shape

Parameters
  • position – The position as 2-tuple

  • thickness – The thickness of the point (1: pixel, >1: The point is rendered as circle)

  • color – The color as 4-tuple (r, g, b, alpha)

Examples

Creates a red point at position (200,100):

>>> Point((200, 100), 1, color=(255,0,0,255))

Circle

class miniworldmaker.tokens.shapes.Circle(position=None, radius=10, thickness=1, color=(255, 255, 255, 255))[source]

A Circle-Shape.

Parameters
  • position – The position as 2-tuple. The circle is created with its center at the position

  • radius – The radius of the circle

  • thickness – The thickness of the bounding line (0: The object is filled)

  • color – The color as 4-tuple (r, g, b, alpha)

Examples

Example Creation of a circle

>>> Circle((200, 100), 20, 1, color=(255,0,0,255))
Creates a red circle at position (200,100) with radius 20

Example Creation of a filled circle

>>> Circle((200, 100), 20, 0, color=(255,0,0,255))
Creates a red circle at position (200,100) with radius 20. The circle is filled
classmethod from_center(position=None, radius=10, thickness=1, color=(255, 255, 255, 255))[source]

Creates a token with center at center_position

Parameters

center_position – Center of token

property radius

Gets the radius of the circle. If you change the circle-size (e.g. with self.size = (x, y), the radius value will be changed too.

Returns: The radius

Line

class miniworldmaker.tokens.shapes.Line(start_position, end_position, thickness=1, color=(255, 255, 255, 255))[source]

A Line-Shape.

Parameters
  • start_position – The start_position as 2-tuple.

  • end_position – The end_position as 2-tuple.

  • thickness – The thickness of the bounding line

  • color – The color as 4-tuple (r, g, b, alpha)

Examples

Example Creation of a line

>>> Line((200, 100), (400,100), 1, color=(255,0,0,255))
Creates a line from (200, 100) to (400, 100)

Rectangle

class miniworldmaker.tokens.shapes.Rectangle(topleft, width, height, thickness=1, color=(255, 255, 255, 255))[source]

A Rect-Shape.

Parameters
  • topleft – Topleft Position of Rect

  • height – The height of the rect

  • width – The width of the rect

  • thickness – The thickness of the bounding line

  • color – The color as 4-tuple (r, g, b, alpha)

Examples

Example Creation of a polygon

>>> Rectangle((200, 100), 10, 10, 1, color=(255,0,0,255))
Creates a red rect with the topleft position (200, 100), the height 10 and the width 10
classmethod from_center(center, width, height, thickness=1, color=(255, 255, 255, 255))[source]

Creates a token with center at center_position

Parameters

center_position – Center of token

Polygon

class miniworldmaker.tokens.shapes.Polygon(pointlist, thickness=1, color=(255, 255, 255, 255))[source]

A Polygon-Shape.

Parameters
  • point-list – A list of points

  • thickness – The thickness of the bounding line

  • color – The color as 4-tuple (r, g, b, alpha)

Examples

Example Creation of a polygon

>>> Polygon([(200, 100), (400,100), (0, 0)], 1, color=(255,0,0,255))
Creates a red polygon with the vertices (200, 100) , (400, 100) and (0, 0)

Example Creation of a filled polygon

>>> Polygon([(200, 100), (400,100), (0, 0)], 0, color=(255,0,0,255))
Creates a red polygon with the vertices (200, 100) , (400, 100) and (0, 0)