Matrix animation effect in JavaScript using Canvas
npm install cmatrix
- ES Module (custom characters)
- ES5
- Matrix Font
You can use CDN:
<script src="https://cdn.jsdelivr.net/npm/cmatrix"></script>and intialize the effect.
matrix(canvasElement, {
chars: ['0', '1'],
font_size: 16
}).matrix(canvasElement, {
chars: matrix.range(0x30A1, 0x30F6).concat(matrix.range(0x0030, 0x0039)),
font_size: 16
}).The matrix function return a Promise that is resolved when exit.
By default, q and ESC exit from the effect. Use exit: false to disable ending the animation.
chars- array of single character strings, by default Katagana and Hiragana (Japanese characters are used).exit- by default matrix return a promise that resolves when it ends (when someone pressqorESC) this option when set to false will disable this and the function return undefined.color- default color - default is#0f0.background- by default it's setrgba(0, 0, 0, 0.05)alpha is required for the effect to look good.font_size- number the default is 14.font- name of the font (defaultmonospace).
matrix.range(start_number, end_number)- returns characters created from given range. Usematrix.range(0x30A1, 0x30F6)for Katagana characters andmatrix.range(0x3041, 0x3096)for Hiragana, they look nice as matrix rain.
- fix clearing state on subsequent calls to matrix #2
- add support for custom font
- add
exit/color/backgroundoptions
- Initial version
- The base code and initial idea came from this Code Pen Demo by Michael Goodman.
- Custom matrix font taken from Realistic Matrix effect.
Copyright (C) 2021-2023 Jakub T. Jankiewicz
Released under MIT License