Rough.js:创建具有手绘、粗略外观的图形
Rough.js: Create graphics with a hand-drawn, sketchy, appearance

原始链接: https://roughjs.com/

隆重推出 Rough.js - 一种向画布或 svg 项目添加粗略手绘风格视觉效果的微小而轻松的方法! 这个多功能图形库可以通过其简单的 API 创建直线、曲线、圆弧、多边形、圆形以及 svg 路径元素。 借助填充、笔画粗细调整、弯曲效果甚至支持模拟手绘等功能,创建具有视觉吸引力的草图从未如此简单。 无论您想要添加细微的变化、阴影还是渐变,rough.js 都提供各种填充类型,例如阴影、实心、锯齿形剖面线、点、旭日形、虚线或锯齿线。 请访问我们的网站以获取完整的文档、示例和制作人员名单。 通过 github 赞助商或开放集体赞助该项目来支持我们。 今天就开始尝试吧! #creativityinmotion #diydesigns #visualstorytelling

一种潜在的解决方案可能涉及使用专门的软件,例如 Topaz Labs,它提供了专门为增强和完善手绘草图而设计的工具。 这些程序利用先进的算法来识别线条并调整其锐度和清晰度。 此外,一些图形设计程序提供类似的功能,包括 Adob​​e Photoshop 的智能锐化滤镜、GIMP 的高通滤镜插件和 Inkscape 的位图跟踪功能。 然而,这些方法需要熟练的技术、耐心和实践才能达到最佳结果。 对于更简单的需求,在重新绘图或复制时结合放大靠近艺术品、数字放大以及手动调整墨水流量和压力也可以产生可接受的结果。 最终,选择的方法取决于每个项目的具体要求和目标。
相关文章

原文

Rough.js

Rough.js is a small (sketchy, hand-drawn-like, style. The library defines primitives to draw lines, curves, arcs, polygons, circles, and ellipses. It also supports drawing SVG paths.

Rough.js works with both Canvas and SVG.

Rough.js sample

Install

Install from npm:

npm install --save roughjs

And use it in your code:

import rough from 'roughjs';

Usage

View Full Rough.js API is available on Github.

Rough.js rectangle

const rc = rough.canvas(document.getElementById('canvas'));
rc.rectangle(10, 10, 200, 200);

or SVG

const rc = rough.svg(svg);
let node = rc.rectangle(10, 10, 200, 200);
svg.appendChild(node);

Lines and Ellipses

Rough.js rectangle

rc.circle(80, 120, 50); 
rc.ellipse(300, 100, 150, 80);
rc.line(80, 120, 300, 100);

Filling

Rough.js rectangle

rc.circle(50, 50, 80, { fill: 'red' }); 
rc.rectangle(120, 15, 80, 80, { fill: 'red' });
rc.circle(50, 150, 80, {
fill: "rgb(10,150,10)",
fillWeight: 3
});
rc.rectangle(220, 15, 80, 80, {
fill: 'red',
hachureAngle: 60,
hachureGap: 8
});
rc.rectangle(120, 105, 80, 80, {
fill: 'rgba(255,0,200,0.2)',
fillStyle: 'solid'
});

Fill styles can be: hachure(default), solid, zigzag, cross-hatch, dots, sunburst, dashed, or zigzag-line

Rough.js fill examples

Sketching style

Rough.js rectangle

rc.rectangle(15, 15, 80, 80, { roughness: 0.5, fill: 'red' });
rc.rectangle(120, 15, 80, 80, { roughness: 2.8, fill: 'blue' });
rc.rectangle(220, 15, 80, 80, { bowing: 6, stroke: 'green', strokeWidth: 3 });

SVG Paths

Rough.js rectangle

rc.path('M80 80 A 45 45, 0, 0, 0, 125 125 L 125 80 Z', { fill: 'green' });
rc.path('M230 80 A 45 45, 0, 1, 0, 275 125 L 275 80 Z', { fill: 'purple' });
rc.path('M80 230 A 45 45, 0, 0, 1, 125 275 L 125 230 Z', { fill: 'red' });
rc.path('M230 230 A 45 45, 0, 1, 1, 275 275 L 275 230 Z', { fill: 'blue' });

SVG Path with simplification:

Rough.js rectangle Rough.js rectangle

Examples

Rough.js map

View examples here

API & Documentation

Full Rough.js API

Credits

Core algorithms for drawing lines and ellipse outlines were adapted from handy processing lib.

Algorithm to convert SVG arcs to Canvas described here was adapted from Mozilla codebase

Support this project

Support development of this project by sponsoring on Github Sponsors.
Alternatively, you can also sponsor or Open Collective.

This project is supported by:

License

MIT License (c) Preet Shihn

联系我们 contact @ memedata.com