Actor > Shapes#

Shape actors are drawable actors with geometry-focused APIs.

API Reference#

Shape#

Base class for shape actors.

class miniworlds.actors.shapes.shapes.Shape(position=(0, 0), *args, **kwargs)[source]#

Base class for geometric actors.

Shapes share the common actor appearance properties border, is_filled, fill_color, and border_color.

Examples

shape.fill_color = (255, 0, 0)
shape.border = 2
get_costume_class()[source]#
Return type:

ShapeCostume

new_costume()[source]#

Create and attach a new empty costume to this actor.

Return type:

ShapeCostume

Point#

class miniworlds.actors.shapes.shapes.Point(position)[source]#

Circle with radius 1.

Parameters:

position – Point position as (x, y).

Examples

point = Point((10, 10))
__init__(position)[source]#

Create a point at a position.

Circle#

class miniworlds.actors.shapes.shapes.Circle(position=(0.0, 0.0), radius=10.0, *args, **kwargs)[source]#

Circular shape.

Parameters:
  • position – Center position as (x, y).

  • radius – Circle radius in pixels.

Examples

circle = Circle((200, 100), 20)
circle.fill_color = (255, 0, 0)

circle = Circle.from_topleft((100, 100), 50)
__init__(position=(0.0, 0.0), radius=10.0, *args, **kwargs)[source]#

Create a circle.

Parameters:
  • position – Center position as (x, y).

  • radius – Circle radius in pixels.

classmethod from_center(position, radius, **kwargs)[source]#

Create a circle positioned by its center.

Parameters:
  • position – Center position as (x, y).

  • radius – Circle radius in pixels.

Returns:

The created circle.

classmethod from_topleft(position, radius, **kwargs)[source]#

Create a circle positioned by its top-left corner.

Parameters:
  • position – Top-left position as (x, y).

  • radius – Circle radius in pixels.

Returns:

The created circle.

get_costume_class()[source]#
Return type:

type[costume_mod.Costume]

new_costume()[source]#

Create and attach a new empty costume to this actor.

property radius#

Circle radius in pixels.

Examples

circle.radius = 30
Type:

float

Ellipse#

class miniworlds.actors.shapes.shapes.Ellipse(position=(0, 0), width=10, height=10, *args, **kwargs)[source]#

Elliptic shape.

Parameters:
  • position – Top-left position as (x, y).

  • width – Ellipse width in pixels.

  • height – Ellipse height in pixels.

Examples

ellipse = Ellipse((200, 100), 20, 30)
ellipse = Ellipse.from_center((100, 100), 10, 10)
check_arguments(position, width, height)[source]#

Validate constructor arguments for Ellipse.

Parameters:
  • position – Position as (x, y).

  • width – Ellipse width in pixels.

  • height – Ellipse height in pixels.

Raises:

EllipseWrongArgumentsError – If position is not a tuple.

classmethod from_center(position, width, height, **kwargs)[source]#

Create an ellipse positioned by its center.

classmethod from_topleft(position, width, height, **kwargs)[source]#

Create an ellipse positioned by its top-left corner.

get_costume_class()[source]#
Return type:

type[costume_mod.Costume]

new_costume()[source]#

Create and attach a new empty costume to this actor.

Line#

class miniworlds.actors.shapes.shapes.Line(start_position, end_position, *args, **kwargs)[source]#

Line shape between two positions.

Parameters:
  • start_position – Start position as (x, y).

  • end_position – End position as (x, y).

Examples

line = Line((200, 100), (400, 100))
line.border = 2
property border#

Line thickness in pixels.

Type:

float

property direction#

Actor direction in Miniworlds/Scratch convention.

Common values are 0 or “up”, 90 or “right”, -90 or “left”, and 180 or “down”.

Examples

@player.register
def on_key_down(self, key):
    if "left" in key:
        self.direction = "left"
    elif "right" in key:
        self.direction = "right"
    self.move()

actor.direction = 45
actor.move()
Type:

int

property end#

End point as (x, y).

Type:

tuple[float, float]

property end_position#

End point as (x, y).

Type:

tuple[float, float]

get_bounding_box()[source]#

Return the rectangular bounding box that contains the line.

Returns:

Bounding rectangle including line thickness.

get_costume_class()[source]#
Return type:

type[costume_mod.Costume]

property length#

Current line length in pixels.

Type:

float

property line_width#

Line thickness in pixels.

Type:

float

new_costume()[source]#

Create and attach a new empty costume to this actor.

property start#

Start point as (x, y).

Type:

tuple[float, float]

property start_position#

Start point as (x, y).

Type:

tuple[float, float]

property thickness#

Line thickness in pixels.

Type:

float

Rectangle#

class miniworlds.actors.shapes.shapes.Rectangle(position=(0, 0), width=10, height=10, *args, **kwargs)[source]#

Rectangular shape.

Parameters:
  • position – Top-left position as (x, y).

  • width – Rectangle width in pixels.

  • height – Rectangle height in pixels.

Examples

rectangle = Rectangle((200, 100), 20, 10)
classmethod from_center(position, width, height)[source]#

Create a rectangle positioned by its center.

classmethod from_topleft(position, width, height)[source]#

Create a rectangle positioned by its top-left corner.

get_costume_class()[source]#
Return type:

type[costume_mod.Costume]

new_costume()[source]#

Create and attach a new empty costume to this actor.

Polygon#

class miniworlds.actors.shapes.shapes.Polygon(position: Tuple[float, float] | None = (0, 0), *args, **kwargs)[source]#

Polygon shape.

Parameters:

pointlist – List of corner points.

Examples

polygon = Polygon([(200, 100), (400, 100), (0, 0)])
polygon.fill_color = (255, 0, 0)
property pointlist#

Polygon corner points.

Type:

list[tuple[float, float]]

Triangle#

class miniworlds.actors.shapes.shapes.Triangle(p1, p2, p3, *args, **kwargs)[source]#

A triangle shape defined by three corner points.

Parameters:
  • p1 – First corner as (x, y).

  • p2 – Second corner as (x, y).

  • p3 – Third corner as (x, y).

Examples

triangle = Triangle((100, 50), (50, 150), (150, 150))
triangle.fill_color = (255, 165, 0)

Arc#

class miniworlds.actors.shapes.shapes.Arc(position=(0, 0), width=10, height=10, start_angle=0, end_angle=0, *args, **kwargs)[source]#

Elliptic arc shape.

Parameters:
  • position – Top-left position as (x, y).

  • width – Arc width in pixels.

  • height – Arc height in pixels.

  • start_angle – Start angle in degrees.

  • end_angle – End angle in degrees.

Examples

arc = Arc((20, 20), 100, 60, 0, 180)
property end_angle#

End angle in degrees.

Type:

float

classmethod from_center(position, width, height, start_angle=0, end_angle=360, **kwargs)[source]#

Create an arc positioned by its center.

property start_angle#

Start angle in degrees.

Type:

float