How to Scale SVG Elements
Rotation is not the only way we can generate images from simple shapes. In this example, we define a tree shape and then place it at various positions in different sizes to draw a forest.
First, we create a background out of a rectangle and a circle.
Then we define a tree shape from a simple polygon and a line.
This tree shape, however, shouldn’t appear on the UI like this.
We can hide it by moving the entire tree into the defs
section. The defs
section is a hidden compartment of our image. Things here don’t show up on the screen, but we can refer to them and use them later.
Then, we can reuse it similarly as in the snowflake example. We wrap the two elements into a group, set an id
, and then reuse it with the use
element.
Here, we also position the reused elements by setting an x
and y
coordinate, and we use the scale
transformation to add some perspective to the image.