Actor > Shapes#
Shape actors are drawable actors with geometry-focused APIs.
API Reference#
Shape#
Base class for shape actors.
Point#
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.
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.
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 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:
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.
Polygon#
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)