Description
Scrawl-canvas is a JavaScript library designed to make using the HTML5 canvas element a bit easier, and a bit more fun!
- Adds functionality to make elements responsive, adapting their size and display according to their surrounding environment.
- Makes the canvas both accessible, and interactive - including the ability to easily track user interactions with different parts of the canvas.
- Defines a set of factory functions to create a wide range of graphic artefacts and effects - including multiline text, animated gradients and adaptable filters - which can be drawn on a canvas.
- Includes an adaptable - yet easy to use - protocol to position, display and animate artefacts and effects across the canvas.
- Builds, controls and animates many canvases across a web page.
Version: 8.4.0 - 2 Feb 2021
Scrawl-canvas Library alternatives and similar libraries
Based on the "Animations" category.
Alternatively, view Scrawl-canvas alternatives based on common mentions on social networks and blogs.
-
animate.css
🍿 A cross-browser library of CSS animations. As easy to use as an easy thing. -
particles.js
A lightweight JavaScript library for creating particles -
GreenSock-JS
GreenSock's GSAP JavaScript animation library (including Draggable). -
Effeckt.css
A Performant Transitions and Animations Library -
barbajs
Create badass, fluid and smooth transitions between your website’s pages. -
jquery.transit
Super-smooth CSS3 transformations and transitions for jQuery -
Dynamic.js
Javascript library to create physics-based animations -
AutoAnimate
A zero-config, drop-in animation utility that adds smooth transitions to your web app. You can use it with React, Vue, or any other JavaScript application. -
bounce.js
Create beautiful CSS3 powered animations in no time. -
tsParticles
tsParticles - Easily create highly customizable JavaScript particles effects, confetti explosions and fireworks animations and use them as animated backgrounds for your website. Ready to use components available for React.js, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Inferno, Solid, Riot and Web Components. -
smoothState.js
Unobtrusive page transitions with jQuery. -
animatable
One property, two values, endless possiblities -
Vizzu
Library for animated data visualizations and data stories. -
Odoo
Javascript and SVG odometer effect library with motion blur -
motus
Animation library that mimics CSS keyframes when scrolling. -
particles-bg
React particles animation background component -
AniX
🐿 Super easy and lightweight(<3kb) JavaScript animation library -
shuffle-images
The Simplest Way to shuffle through images in a Creative Way -
Scroll Btween
ScrollBtween uses scroll position of document - or any DOM element - to tween CSS values on any DOM element. -
TransitionEnd
:dizzy: TransitionEnd is an agnostic and cross-browser library to work with transitionend event. -
Tailwind Animations
Tailwind animations examples -
js-loading-overlay
Display loading overlay/spinner for your application easily and beautifully. -
Scroll Frames
Animate sequences of still frames on any DOM element in relation with its position into the viewport. https://olivier3lanc.github.io/Scroll-Frames/
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Scrawl-canvas Library or a related project?
README
Welcome to the Scrawl-canvas Library
Version: 8.8.1 - 27 Mar 2022
Scrawl-canvas website: scrawl-v8.rikweb.org.uk.
- learning materials: scrawl-v8.rikweb.org.uk/learn.
- documentation: scrawl-v8.rikweb.org.uk/documentation.
- tests/demos: scrawl-v8.rikweb.org.uk/demonstrations.
Scrawl-canvas on CodePen: codepen.io/collection/RzzMjw.
Scrawl-canvas on Discord: discord.com/channels/...
Do you want to contribute? Don't be afraid - reach out and let's see what website magic we can create together!
What?
Scrawl-canvas is a Javascript library for working with the HTML5 <canvas> element. The library:
- Defines a set of factory functions for creating a wide range of graphic artefacts and effects, which can be drawn on a canvas.
- Includes an adaptable - yet easy to use - protocol for positioning, displaying and animating artefacts and effects across the canvas.
- Adds functionality to make <canvas> elements
responsive
, adapting their size to their surrounding environment while remaining fullyinteractive
. - Helps make canvas elements more
accessible
for both keyboard and AT users.
https://user-images.githubusercontent.com/5357530/141673995-df239c38-2ba1-43f3-831c-b655524f2f40.mp4
Why?
Working with the native Canvas API is hard work - particularly when the desired result is more complex than a couple of coloured boxes in a static display.
But the benefits of using canvases for graphical displays and animations are also great:
- Canvases are part of the DOM (unlike Flash);
- They are natively wired for events and user interactions;
- They use immediate mode redering (which makes them very quick); and
- The canvas-related APIs are designed to be used with Javascript.
Sadly these advantages are also significant barriers:
- Working directly with the canvas-related APIs means writing significant amounts of Javascript boilerplate code.
- <canvas> elements can be resized and styled using CSS, but changing the CSS size does not affect the element's drawing dimensions - leading to ugly results.
- Events work on the canvas, not on the graphical objects within the canvas - we cannot use those objects as links or hot-spots (click/tap events), we cannot give them the equivalent of a CSS hover state (focus/blur events), we cannot drag-and-drop them around the display (move events).
- Tracking a user's interaction with the various parts of a canvas display, for analytics and research on web page performance, is particularly difficult.
- We cannot easily save and share displays, effects and animations; each <canvas> element's output is tightly coupled to the code that defines that output.
- Of most concern, canvases are entirely graphical - visual - by nature; they come with significant accessibility issues. Given the ever-stricter requirements for websites to be accessible to all users, this makes using a canvas to present important information a dangerous proposition.
Scrawl-canvas overcomes these barriers
Scrawl-canvas is fast, and developer-friendly. It's suitable for building infographics, games, interactive videos - whatever we can imagine for a 2D graphical presentation. And it is modular - we can break the code for a particular effect into its own module file which can be reused in other projects.
Scrawl-canvas offers all of this while never losing its hard focus on making the <canvas> element accessible, responsive and fully interactive
while at the same time offering a pleasant developer experience
.
Also, Scrawl-canvas supports developers coding in TypeScript by means of a TS definitions file included in the repository.
Installation and use
There are three main ways to include Scrawl-canvas in your project:
Download, unpack, use
- Download the zipped file from GitHub
- Unzip the file to a folder in your project.
- Import the library into the script code where you will be using it.
Alternatively, a zip package of the v8.8.1 files can be downloaded from this link: scrawl.rikweb.org.uk/downloads/scrawl-canvas_8-8-1.zip - that package only includes the minified file.
<!-- Hello world -->
<!DOCTYPE html>
<html>
<head>
<title>Scrawl-canvas Hello World</title>
</head>
<body>
<canvas id="mycanvas"></canvas>
<!-- The library is entirely modular and needs to be imported into a module script -->
<script type="module">
import * as scrawl from './relative-or-absolute/path/to/scrawl-canvas/min/scrawl.js';
// Get a handle to the canvas element
let canvas = scrawl.library.canvas.mycanvas;
// Setup the scene to be displayed in the canvas
scrawl.makePhrase({
name: 'hello',
text: 'Hello, World!',
width: '100%',
startX: 20,
startY: 20,
font: 'bold 40px Garamond, serif',
});
// Render the canvas scene once
canvas.render();
</script>
</body>
</html>
CDN - unpkg.com
This will pull the requested npm package directly into your web page:
<script type="module">
import * as scrawl from 'https://unpkg.com/[email protected]';
[...]
</script>
NPM/Yarn
- Add the library to your project using NPM or Yarn
- Import the library into the script code where you will be using it.
// either
$> npm install scrawl-canvas
// or
$> yarn add scrawl-canvas
// then in your script file
import * as scrawl from 'scrawl-canvas';
// Scrawl-canvas has no dependencies
// - it can be used as-is, with no further installation steps required
Local development and testing
After forking this repo down to your local machine, cd
into the scrawl-canvas folder, run yarn install
or npm install
(for the local build toolchain - the library itself has no external dependencies) and start a local server. For instance if you have light-server installed:
$> cd ./path/to/Scrawl-canvas
$> yarn install
$> light-server --serve . --open
light-server is listening at http://0.0.0.0:4000
serving static dir: .
Code visualisation
[Visualization of the codebase](./diagram.svg)
Testing
The code base does not include any unit testing frameworks. Instead, we rely on a set of Demo tests which allow us to perform integration testing and user interface testing.
Why this approach? Because most of the Scrawl-canvas functionality revolves around various forms of animation, which requires visual inspection of the Demo tests to check that the canvas display - and thus, by inference, the underlying code - performs as expected.
Most Demos include some form of user interaction, which allows us to test specific aspects of the code base.
TypeScript support
Scrawl-canvas supports TypeScript through a TypeScript Definitions (d.ts) file. The definitions file aims to be as accurate, comprehensive and informative as possible, but specifically excludes support for internal (private) SC object attributes and functions.
To aid development, we test the definitions file against the entire suite of Demo code .js files supplied as part of the library. From the root of the project, run the following command:
$> yarn test
Documentation
The source code has been extensively commented. We generate documentation from that code using Docco. Documentation is regenerated each time the library is rebuilt.
Minification
We minify the source code using rollup and its terser plugin.
Building the library
Running the following command on the command line will recreate the minified file, and regenerate the documentation:
$> yarn build
Development team
Developed by Rik Roots: [email protected]