Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

50.13.1Shapes drawing

We define first the Shape trait:

Then the rectangle:

Its implementation:

The Circle structure:

Its implementation:

The Drawing contains now a shapes field that is a vector of shapes:

In the implementation of the Drawing structure, we now have a draw() method that iterates over all shapes to call their draw() methods, and a add_shape() method to add new shapes:

Let us instantiate a rectangle and a circle:

We then create the Drawing object and add our shapes to it, and finally trigger the drawing:

Drawing rectangle 20x30 at (4, 6).
Drawing circle of radius 10 at (5, 2).
()