Skip to content

Pattern ​

Repeated background filling from an image.

Pattern example

Examples ​

js
import { Pattern, Image, Circle } from "pencil.js";

const position = [100, 100];
const radius = 50;
const patternOptions = {
    repeat: Pattern.repetition.repeat,
    origin: "center",
    scale: 0.5,
};
// Preload the image
Image.load("pattern.png").then((image) => {
    const circle = new Circle(position, radius, {
        fill: new Pattern(image, patternOptions),
    });
});

PatternOptions ​

NameTypeDefaultComment
repeatString"repeat"Repetition rule
originPositionnew Position()Relative offset
scaleNumber or Position1Scaling ratio or a pair of value for horizontal and vertical scaling

Released under the MIT License.