Skip to content
On this page

ImageRepeat Shape

TIP

This class is a descendant of Shape it also inherits all the options that Shape provides.

TIP

This component also supports a return function

A new need arises that when you need something to draw similar to background-repeat use ImageRepeat.

For image property you can use:

image An element to draw into the context. The specification permits any canvas image source, specifically,

In addition, this shape also provides a few other parameters:

Require Options

NameTypeDescription
imageMayBeRef<CanvasImageSource | string>multiply by a value as stated above

Inherit Shape

NameTypeDescription
xMayBeRef<number>offset x
yMayBeRef<number>offset y

Optional Options

NameTypeDefaultDescription
scrollWidthMayBeRef<number>= imageWidthThe width of the element to be visible. for example if scrollWidth=100 the image will be repeatedly drawn until the total size >= 100
scrollHeightMayBeRef<number>= imageHeightThe height of the element to be visible. for example if scrollHeight=100 the image will be repeatedly drawn until the total size >= 100
scrollTopMayBeRef<number>0position y scrolled to it similar to background-position
scrollLeftMayBeRef<number>0position x scrolled to it similar to background-position
whileDrawMayBeRef<boolean>falseIs it constantly redrawing and ignoring the cache policy?

TIP

The crop feature provided by this component is very simple. If you need more powerful cropping (e.g. Tile) use cropImage

Demo

ts
import { Stage, Layer, ImageRepeat, loadImage } from "fcanvas"

const stage = new Stage().mount("#app")
const layer = new Layer().addTo(stage)

const image = new ImageRepeat({
  x: stage.size.width / 2,
  y: stage.size.height / 2,
  image: await loadImage("https://google.com/favicon.ico"),
  scrollWidth: 300,
  scrollHeight: 150,
  scrollTop: 20
}).addTo(layer)

Released under the MIT License.