Simple, light-weight, Canvas library for 2D rendering
-
ChainAPI -
Drawing
actionsreusable -
Same methods as CanvasRenderingContext2D
npm install we-render- ES6 module
import { WeCanvas, WeStage } from 'we-render'
const child = new WeCanvas()
.setSize(100, 100)
.scale(2, 2)
.fillStyle("red") // different here
.fillRect(0, 0, 10, 10)
const stage = new WeStage()
stage.addChid(child)
stage.update()- In browser
<script type="text/javascript" src="../dist/weRender.min.js"></script>
<script type="text/javascript">
var WeStage = weRender.WeStage;
var WeCanvas = weRender.WeCanvas;
var stage = new WeStage(document.querySelector("#canvas"));
stage.setSize(500, 500);
stage.setStyle("500px", "500px");
var yellowCircle = new WeCanvas({
width: 100,
height: 100,
})
.beginPath()
.fillStyle("yellow")
.arc(50, 50, 50, 0, 2 * Math.PI)
.fill()
stage.addChild(yellowCircle);
stage.update();
</script>See examples:
npm run static
Usefull Scripts for improving efficiency.
SVG to Canvas
See: https://github.com/weiying-shenzhen/svgToCanvas
Examples:
See examples under directoryexamples/path
- weRender
weRender: Simple Canvas library for easy usage
- WeCanvas
WeCanvas: Easy canvas api for using, support useing chain
- Directly use CanvasRenderingContext2D
methods PropertyofCanvasRenderingContext2Dhere ismethod- Won't really drawing Canvas until run
draw()
- Directly use CanvasRenderingContext2D
- WeStage
WeStage: Canvas manager for WeCanvas
weRender: Simple Canvas library for easy usage
WeCanvas: Easy canvas api for using, support useing chain
- Directly use CanvasRenderingContext2D
methods PropertyofCanvasRenderingContext2Dhere ismethod- Won't really drawing Canvas until run
draw()
Kind: global class
create a WeCanvas instance
| Param | Type | Description |
|---|---|---|
| options | Object |
option settions for instance |
set canvas size
Kind: instance method of WeCanvas
| Param | Type | Description |
|---|---|---|
| width | Number |
canvas width |
| height | Number |
canvas height |
set canvas style, only width and height
Kind: instance method of WeCanvas
| Param | Type | Description |
|---|---|---|
| width | String |
canvas style width |
| height | String |
canvas style height |
set coordinate of stage
Kind: instance method of WeCanvas
| Param | Type | Default | Description |
|---|---|---|---|
| x | Number |
0 |
horizontal axis |
| y | Number |
0 |
vertical axis |
set init scale
Kind: instance method of WeCanvas
| Param | Type | Description |
|---|---|---|
| scale | Number |
scale ratio |
clear canvas
Kind: instance method of WeCanvas
get actions for context drawing
Kind: instance method of WeCanvas
set actions
Kind: instance method of WeCanvas
| Param | Type | Description |
|---|---|---|
| actions | Array |
actions for context drawing |
run actions, draw canvas
Kind: instance method of WeCanvas
set cache, default: true
Kind: instance method of WeCanvas
| Param | Type | Default | Description |
|---|---|---|---|
| ifCache | Boolean |
true |
if set cache |
WeStage: Canvas manager for WeCanvas
Kind: global class
create a WeStage instance
| Param | Type | Description |
|---|---|---|
| canvas | Canvas |
a Canvas element related to the dom |
| options | Object |
stage settings |
set stage size
Kind: instance method of WeStage
| Param | Type | Description |
|---|---|---|
| width | Number |
stage width |
| height | Number |
stage height |
set stage style
Kind: instance method of WeStage
| Param | Type | Description |
|---|---|---|
| width | String |
stage style width |
| height | String |
stage style height |
destrory stage
Kind: instance method of WeStage
clear canvas
Kind: instance method of WeStage
add child to the stage
Kind: instance method of WeStage
| Param | Type | Description |
|---|---|---|
| child | WeCanvas | Object |
WeCanvas instance or Object cotains Canvas |
translate stage, move coordinate
Kind: instance method of WeStage
| Param | Type | Default | Description |
|---|---|---|---|
| x | Number |
0 |
offset x |
| y | Number |
0 |
offset y |
| reset | Boolean |
false |
should reset after update |
update stage, draw child on canvas run this method, all child canvas will draw
Kind: instance method of WeStage
docs autogenerated via jsdoc2md