# weRender **Repository Path**: kevin402502/weRender ## Basic Information - **Project Name**: weRender - **Description**: Simple, light-weight, Canvas library for 2D rendering - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-17 - **Last Updated**: 2021-06-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # weRender Simple, light-weight, Canvas library for 2D rendering # Features - `Chain` API - Drawing `actions` reusable - Same methods as CanvasRenderingContext2D # Install ```shell npm install we-render ``` # Usage - **ES6 module** ```javascript 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** ```html ``` # Examples See examples: `npm run static` * simple * clone * reuse actions * composite * zoom # Scripts Usefull Scripts for improving efficiency. **`SVG` to `Canvas`** See: https://github.com/weiying-shenzhen/svgToCanvas Examples: See examples under directory`examples/path` # API reference ## Modules
weRender

weRender: Simple Canvas library for easy usage

## Classes
WeCanvas

WeCanvas: Easy canvas api for using, support useing chain

WeStage

WeStage: Canvas manager for WeCanvas

## weRender weRender: Simple Canvas library for easy usage ## WeCanvas WeCanvas: Easy canvas api for using, support useing chain - Directly use CanvasRenderingContext2D` methods` - `Property` of `CanvasRenderingContext2D` here is `method` - Won't really drawing Canvas until run `draw()` **Kind**: global class * [WeCanvas](#WeCanvas) * [new WeCanvas(options)](#new_WeCanvas_new) * [.setSize(width, height)](#WeCanvas+setSize) * [.setStyle(width, height)](#WeCanvas+setStyle) * [.setCoordinate(x, y)](#WeCanvas+setCoordinate) * [.setScale(scale)](#WeCanvas+setScale) * [.clear()](#WeCanvas+clear) * [.getActions()](#WeCanvas+getActions) * [.setActions(actions)](#WeCanvas+setActions) * [.draw()](#WeCanvas+draw) * [.cache(ifCache)](#WeCanvas+cache) ### new WeCanvas(options) create a WeCanvas instance | Param | Type | Description | | --- | --- | --- | | options | Object | option settions for instance | ### weCanvas.setSize(width, height) set canvas size **Kind**: instance method of [WeCanvas](#WeCanvas) | Param | Type | Description | | --- | --- | --- | | width | Number | canvas width | | height | Number | canvas height | ### weCanvas.setStyle(width, height) set canvas style, only width and height **Kind**: instance method of [WeCanvas](#WeCanvas) | Param | Type | Description | | --- | --- | --- | | width | String | canvas style width | | height | String | canvas style height | ### weCanvas.setCoordinate(x, y) set coordinate of stage **Kind**: instance method of [WeCanvas](#WeCanvas) | Param | Type | Default | Description | | --- | --- | --- | --- | | x | Number | 0 | horizontal axis | | y | Number | 0 | vertical axis | ### weCanvas.setScale(scale) set init scale **Kind**: instance method of [WeCanvas](#WeCanvas) | Param | Type | Description | | --- | --- | --- | | scale | Number | scale ratio | ### weCanvas.clear() clear canvas **Kind**: instance method of [WeCanvas](#WeCanvas) ### weCanvas.getActions() get actions for context drawing **Kind**: instance method of [WeCanvas](#WeCanvas) ### weCanvas.setActions(actions) set actions **Kind**: instance method of [WeCanvas](#WeCanvas) | Param | Type | Description | | --- | --- | --- | | actions | Array | actions for context drawing | ### weCanvas.draw() run actions, draw canvas **Kind**: instance method of [WeCanvas](#WeCanvas) ### weCanvas.cache(ifCache) set cache, default: true **Kind**: instance method of [WeCanvas](#WeCanvas) | Param | Type | Default | Description | | --- | --- | --- | --- | | ifCache | Boolean | true | if set cache | ## WeStage WeStage: Canvas manager for WeCanvas **Kind**: global class * [WeStage](#WeStage) * [new WeStage(canvas, options)](#new_WeStage_new) * [.setSize(width, height)](#WeStage+setSize) * [.setStyle(width, height)](#WeStage+setStyle) * [.destory()](#WeStage+destory) * [.clear()](#WeStage+clear) * [.addChild(child)](#WeStage+addChild) * [.translate(x, y, reset)](#WeStage+translate) * [.update()](#WeStage+update) ### new WeStage(canvas, options) create a WeStage instance | Param | Type | Description | | --- | --- | --- | | canvas | Canvas | a Canvas element related to the dom | | options | Object | stage settings | ### weStage.setSize(width, height) set stage size **Kind**: instance method of [WeStage](#WeStage) | Param | Type | Description | | --- | --- | --- | | width | Number | stage width | | height | Number | stage height | ### weStage.setStyle(width, height) set stage style **Kind**: instance method of [WeStage](#WeStage) | Param | Type | Description | | --- | --- | --- | | width | String | stage style width | | height | String | stage style height | ### weStage.destory() destrory stage **Kind**: instance method of [WeStage](#WeStage) ### weStage.clear() clear canvas **Kind**: instance method of [WeStage](#WeStage) ### weStage.addChild(child) add child to the stage **Kind**: instance method of [WeStage](#WeStage) | Param | Type | Description | | --- | --- | --- | | child | [WeCanvas](#WeCanvas) \| Object | WeCanvas instance or Object cotains Canvas | ### weStage.translate(x, y, reset) translate stage, move coordinate **Kind**: instance method of [WeStage](#WeStage) | Param | Type | Default | Description | | --- | --- | --- | --- | | x | Number | 0 | offset x | | y | Number | 0 | offset y | | reset | Boolean | false | should reset after update | ### weStage.update() update stage, draw child on canvas **run this method, all child canvas will draw** **Kind**: instance method of [WeStage](#WeStage) *docs autogenerated via [jsdoc2md](https://github.com/jsdoc2md/jsdoc-to-markdown)*