npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tbminiapp/pixi-plugin-calligraphy

v1.0.0

Published

The PIXI plugin for calligraphy

Downloads

2

Readme

pixi-plugin-calligraphy

PIXI[FOR 手淘小程序]书法插件,默认使用毛笔

使用方法

npm install @tbminiapp/pixi-plugin-calligraphy -S

1、最简单的例子
import * as calligraphy from "@tbminiapp/pixi-plugin-calligraphy";

const app = new PIXI.Application({
  // ...
});

const container = new PIXI.Container();
// 实例化
const tablet = new calligraphy.Tablet({
  width,
  height,
  resolution: app.renderer.resolution
});

// 开始接受笔画
tablet.start();

container.addChild(tablet);
app.run(container);
2、笔刷相关设置
// 选择笔刷:细
tablet.selectBrush(calligraphy.BRUSH_TYPE.SMALL);

// 设置笔刷墨量:少量
tablet.setBrushInk(calligraphy.BRUSH_INK.LESS);

// 设置压速,值越大,越饱满
tablet.setPressureVelocity(4);
3、清空和撤销
// 清空
tablet.clear();

// 撤销
tablet.undo();
4、获取完整绘制数据
tablet.getHistory();
// => [{"O":0,"D":[{"X":243.95347595214844,"Y":272.40594482421875,"T":8},{...}]}]

数据结构:

// StrokeHistory
[
  // 0: STROKE
  {
    O: STROKE_OPERATION // 值为 0
    D: StrokeData[] // 见下
  },
  // 1: SET_BRUSH
  {
    O: STROKE_OPERATION // 值为 1
    D: BRUSH_TYPE
  },
  // 2: SET_INK
  {
    O: STROKE_OPERATION // 值为 2
    D: BRUSH_INK
  }
]

// StrokeData
{
  P: number // 压力值(暂不支持)
  T: number // 距离第一笔的耗时(累加)
  X: number // 坐标 x
  Y: number // 坐标 y
}
5、事件
// 每一笔的开始事件
tablet.on('stroke-begin', function() {
  console.log('beigin');
});
// 每一笔的结束事件
tablet.on('stroke-end', function(history) {
  console.log(history);
});
6、定制笔的风格

假设你选择了张 50*50 的图片作为笔刷:

// 更改笔刷
calligraphy.BRUSH_SIZE.width = 50;
calligraphy.BRUSH_SIZE.height = 50;

// 这里假设不考虑墨量,即都是一样(当然如果不一样,就改成各自的图片即可)
calligraphy.BRUSH_INK_IMAGE['less'] =
calligraphy.BRUSH_INK_IMAGE['medium'] =
calligraphy.BRUSH_INK_IMAGE['plenty'] = 'data:image/png;base64,iVBORw0KGgoAAA...';

你也可以扩展更多尺寸的笔刷:

// 新增一个笔刷(笔刷名为 CUSTOM,书写过程中的最大尺寸为 30)
calligraphy.Brush.add('custom', 30);

// 使用定义的笔刷
tablet.selectBrush(calligraphy.BRUSH_TYPE.CUSTOM);

你也可以扩展更多墨量的笔刷:

// 增加一个更少墨的笔:FEWER
calligraphy.BRUSH_INK.FEWER = 'fewer';

// 增加这个笔的笔触图片
calligraphy.BRUSH_INK_IMAGE['fewer'] = 'data:image/png;base64,iVBORw0KGgoAAA...';

// 使用这个笔刷
tablet.setBrushInk(calligraphy.BRUSH_INK.FEWER);
7、回放

回放数据的获取:

const data = tablet.getPlainHistory();

创建回放:

const app = new PIXI.Application({
  // ...
});

const container = new PIXI.Container();
// 实例化
const player = new calligraphy.Player({
  width,
  height,
  resolution: app.renderer.resolution
}}, data);

container.addChild(player);
app.run(container);

// 开始播放
player.play();

依赖

  • @tbminiapp/pixi-miniprogram-engine

API文档

  • docs/index.html

写在最后

代码改写于 https://github.com/cobysy/shodo, 代码版权归原作者