Skip to content

Use Graphics component

Common example:

html
<script>
const draw = (g) => {
    g.rect(0, 0, 100, 100).fill('red')
}
</script>

<Graphics @draw />

Example with width and height:

html
<script>
import { signal } from 'canvasengine'

const width = signal(100)
const height = signal(100)

const draw = (g) => {
    g.rect(0, 0, width(), height()).fill('red')
}

const click = () => {
    width.update(w => w + 10)
    height.update(h => h + 10)
}
</script>

<Graphics @draw @click />

the drawing is redrawn if width and height change

Rectangle

html
<Rect x="0" y="0" width="100" height="100" color="red" />

Circle

html
<Circle x="0" y="0" radius="50" color="red" />

Triangle

html
<Triangle x="0" y="0" width="100" height="100" color="red" />

Ellipse

html
<Ellipse x="0" y="0" width="100" height="100" color="red" />

draw

Function that draws on the canvas. It receives the Graphics object as argument. It uses PixiJS Graphics to draw.

Common Properties

PropertyTypeDescription
xnumberX-coordinate position of the display object.
ynumberY-coordinate position of the display object.
widthnumberWidth of the display object.
heightnumberHeight of the display object.
scaleobjectScale of the display object.
anchorobjectAnchor point of the display object.
skewobjectSkew of the display object.
tintnumberTint color of the display object.
rotationnumberRotation of the display object in radians.
anglenumberRotation of the display object in degrees.
zIndexnumberZ-index of the display object.
roundPixelsbooleanWhether to round pixel values.
cursorstringCursor style when hovering over the display object.
visiblebooleanVisibility of the display object.
alphanumberAlpha transparency of the display object.
pivotobjectPivot point of the display object.
flexDirectionstringFlex direction for layout. Possible values: 'row', 'column', 'row-reverse', 'column-reverse'.
flexWrapstringFlex wrap for layout. Possible values: 'wrap', 'nowrap', 'wrap-reverse'.
justifyContentstringJustify content for layout. Possible values: 'flex-start', 'flex-end', 'center', 'space-between', 'space-around'.
alignItemsstringAlign items for layout. Possible values: 'auto', 'flex-start', 'flex-end', 'center', 'stretch', 'baseline', 'space-between', 'space-around'.
alignContentstringAlign content for layout. Possible values: 'flex-start', 'flex-end', 'center', 'stretch', 'baseline', 'space-between', 'space-around'.
alignSelfstringAlign self for layout. Possible values: 'auto', 'flex-start', 'flex-end', 'center', 'stretch', 'baseline', 'space-between', 'space-around'.
marginobjectMargin for layout.
paddingobjectPadding for layout.
gapobjectGap for layout.
borderobjectBorder for layout.
positionTypestringPosition type for layout.
filtersarrayFilters applied to the display object.
maskOfElementElement that this display object masks.
blendModestringBlend mode for rendering.
filterAreaobjectFilter area for rendering.

shadow

PropertyTypeDescription
PropertyTypeDescription
blurnumberBlur strength.
colornumberColor of the shadow.
offsetobjectOffset of the shadow.
qualitynumberQuality of the shadow.