Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
canvas-loop-engine
Advanced tools
Readme
A basic loop engine for canvas animation
npm i canvas-loop-engine --save
or
yarn add canvas-loop-engine
import Engine from "canvas-loop-engine"
const MyLoop = new Engine({ ...options })
MyLoop.start()
Type | Default | required | Description |
---|---|---|---|
HTMLCanvasElement | null | true | The canvas html element you want to draw on. |
import Engine from "canvas-loop-engine"
const MyLoop = new Engine({
$canvas: document.querySelector("canvas")
})
Type | Default | required | Description |
---|---|---|---|
string | "2d" | false | The canvas context type giving in the getContext. See getContext documentation |
import Engine from "canvas-loop-engine"
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
contextType: "webgl"
})
Type | Default | required | Description |
---|---|---|---|
object | null | false | The canvas context attributes giving in the getContext. See getContext documentation |
import Engine from "canvas-loop-engine"
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
contextType: "webgl",
contextAttribute: {
antialias: false,
depth: false
}
})
Type | Default | required | Description |
---|---|---|---|
boolean | true | false | Define if the loop engine should start automaticaly. |
import Engine from "canvas-loop-engine"
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
autoStart: false //default true
})
Type | Default | required | Description |
---|---|---|---|
boolean | true | false | Automaticaly clear the canvas before each draw |
Will trigger just before the onDraw functions
import Engine from "canvas-loop-engine"
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
autoStart: false //default true
})
Type | Default | required | Description |
---|---|---|---|
any | {} | false | You can give a data object. it will be return as argument in every props function (onInit, onUpdate, onDraw, onStar, onStop) for a future usage. |
Usually, you can use it to stock your drawing settings (particles etc...)
⚠️ The data object will be deeply clone. It will break every references
import Engine from "canvas-loop-engine"
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
data: [{
//...particle data
}]
})
Type | Default | required | Description |
---|---|---|---|
function | array of function | null | false | function or array of function that will trigger at the loop init |
name | type | Description |
---|---|---|
$canvas | HTMLCanvasElement | the html convas element |
ctx | HTMLElement | the html convas element |
data | any | the data object you send at the init |
import Engine from "canvas-loop-engine"
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
onInit: function ({ $canvas, ctx, data }) {
//do things
}
})
or
import Engine from "canvas-loop-engine"
const foo = function ({ $canvas, ctx, data }) {
//do things
}
const bar = function ({ $canvas, ctx, data }) {
//do things
}
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
onInit: [foo, bar]
})
Type | Default | required | Description |
---|---|---|---|
function | array of function | null | false | Function or array of function that will trigger when you start the loop |
name | type | Description |
---|---|---|
$canvas | HTMLCanvasElement | the html convas element |
ctx | HTMLElement | the html convas element |
data | any | the data object you send at the init |
import Engine from "canvas-loop-engine"
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
onStart: function ({ $canvas, ctx, data }) {
//do things
}
})
or
import Engine from "canvas-loop-engine"
const foo = function ({ $canvas, ctx, data }) {
//do things
}
const bar = function ({ $canvas, ctx, data }) {
//do things
}
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
onStart: [foo, bar]
})
Type | Default | required | Description |
---|---|---|---|
function | array of function | null | false | Function or array of function that will trigger when you stop the loop |
name | type | Description |
---|---|---|
$canvas | HTMLCanvasElement | the html convas element |
ctx | HTMLElement | the html convas element |
data | any | the data object you send at the init |
import Engine from "canvas-loop-engine"
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
onStop: function ({ $canvas, ctx, data }) {
//do things
}
})
or
import Engine from "canvas-loop-engine"
const foo = function ({ $canvas, ctx, data }) {
//do things
}
const bar = function ({ $canvas, ctx, data }) {
//do things
}
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
onStop: [foo, bar]
})
Type | Default | required | Description |
---|---|---|---|
function | array of function | null | false | Function or array of function that will trigger on each loop update |
name | type | Description |
---|---|---|
$canvas | HTMLCanvasElement | the html convas element |
ctx | HTMLElement | the html convas element |
data | any | the data object you send at the init |
import Engine from "canvas-loop-engine"
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
onUpdate: function ({ $canvas, ctx, data }) {
//do things
}
})
or
import Engine from "canvas-loop-engine"
const foo = function ({ $canvas, ctx, data }) {
//do things
}
const bar = function ({ $canvas, ctx, data }) {
//do things
}
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
onUpdate: [foo, bar]
})
Type | Default | required | Description |
---|---|---|---|
function | array of function | null | false | Function or array of function that will trigger on each draw, usually, it's here you draw on canvas |
name | type | Description |
---|---|---|
$canvas | HTMLCanvasElement | the html convas element |
ctx | HTMLElement | the html convas element |
data | any | the data object you send at the init |
import Engine from "canvas-loop-engine"
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
onDraw: function ({ $canvas, ctx, data }) {
//draw things
}
})
or
import Engine from "canvas-loop-engine"
const foo = function ({ $canvas, ctx, data }) {
//draw things
}
const bar = function ({ $canvas, ctx, data }) {
//draw things
}
const MyLoop = new Engine({
$canvas: document.querySelector("canvas"),
onDraw: [foo, bar]
})
Type | Description |
---|---|
function | Start the loop, if it was'nt already start |
Will trigger the
onStart
functions
Type | Description |
---|---|
function | Stop the loop, if it was'nt already stop |
Will trigger the
onStop
functions
Type | Description |
---|---|
function | Toogle the loop (stop or start) |
Will trigger the
onStop
oronStart
functions
Type | Description |
---|---|
function | trigger the onUpdate functions |
Type | Description |
---|---|
function | trigger the onDraw functions |
Type | Description |
---|---|
boolean | the current loop status (if he's running or not) |
FAQs
A basic loop engine for canvas animation
The npm package canvas-loop-engine receives a total of 13 weekly downloads. As such, canvas-loop-engine popularity was classified as not popular.
We found that canvas-loop-engine demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.