{"id":13984,"date":"2021-03-09T10:30:21","date_gmt":"2021-03-09T09:30:21","guid":{"rendered":"https:\/\/hesmid.nl\/test\/?p=13984"},"modified":"2021-03-09T13:43:11","modified_gmt":"2021-03-09T12:43:11","slug":"rough-js-create-graphics-with-a-hand-drawn-sketchy-appearance","status":"publish","type":"post","link":"https:\/\/hesmid.nl\/test\/rough-js-create-graphics-with-a-hand-drawn-sketchy-appearance\/","title":{"rendered":"rough.js &#8211; create graphics with a hand-drawn, sketchy, appearance"},"content":{"rendered":"\n<p><a href=\"https:\/\/roughjs.com\/\">https:\/\/roughjs.com\/<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Rough.js<\/h2>\n\n\n\n<p><strong>Rough.js<\/strong> is a small (&lt;9kB gzipped) graphics library that lets you draw in a <em>sketchy<\/em>, <em>hand-drawn-like<\/em>, style. The library defines primitives to draw lines, curves, arcs, polygons, circles, and ellipses. It also supports drawing <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/SVG\/Tutorial\/Paths\">SVG paths<\/a>.<\/p>\n\n\n\n<p>Rough.js works with both <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Canvas_API\">Canvas<\/a> and <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/SVG\">SVG<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/roughjs.com\/images\/cap.png\" alt=\"Rough.js sample\"\/><\/figure>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Install<\/h2>\n\n\n\n<p>Install from npm:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm install --save roughjs<\/code><\/pre>\n\n\n\n<p>And use it in your code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import rough from 'roughjs';<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Usage<\/h2>\n\n\n\n<p>View <a href=\"https:\/\/github.com\/rough-stuff\/rough\/wiki\">Full Rough.js API<\/a> is available on Github.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/roughjs.com\/images\/m1.png\" alt=\"Rough.js rectangle\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>const rc = rough.canvas(document.getElementById('canvas'));<br>rc.rectangle(10, 10, 200, 200); \/\/ x, y, width, height<\/code><\/pre>\n\n\n\n<p>or SVG<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const rc = rough.svg(svg);<br>let node = rc.rectangle(10, 10, 200, 200); \/\/ x, y, width, height<br>svg.appendChild(node);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Lines and Ellipses<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/roughjs.com\/images\/m2.png\" alt=\"Rough.js rectangle\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>rc.circle(80, 120, 50); \/\/ centerX, centerY, diameter<br>rc.ellipse(300, 100, 150, 80); \/\/ centerX, centerY, width, height<br>rc.line(80, 120, 300, 100); \/\/ x1, y1, x2, y2<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Filling<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/roughjs.com\/images\/m3.png\" alt=\"Rough.js rectangle\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>rc.circle(50, 50, 80, { fill: 'red' }); \/\/ fill with red hachure<br>rc.rectangle(120, 15, 80, 80, { fill: 'red' });<br>rc.circle(50, 150, 80, {<br>  fill: \"rgb(10,150,10)\",<br>  fillWeight: 3 \/\/ thicker lines for hachure<br>});<br>rc.rectangle(220, 15, 80, 80, {<br>  fill: 'red',<br>  hachureAngle: 60, \/\/ angle of hachure,<br>  hachureGap: 8<br>});<br>rc.rectangle(120, 105, 80, 80, {<br>  fill: 'rgba(255,0,200,0.2)',<br>  fillStyle: 'solid' \/\/ solid fill<br>});<\/code><\/pre>\n\n\n\n<p>Fill styles can be: <strong>hachure<\/strong>(default), <strong>solid<\/strong>, <strong>zigzag<\/strong>, <strong>cross-hatch<\/strong>, <strong>dots<\/strong>, <strong>sunburst<\/strong>, <strong>dashed<\/strong>, or <strong>zigzag-line<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/roughjs.com\/images\/m14.png\" alt=\"Rough.js fill examples\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Sketching style<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/roughjs.com\/images\/m4.png\" alt=\"Rough.js rectangle\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>rc.rectangle(15, 15, 80, 80, { roughness: 0.5, fill: 'red' });<br>rc.rectangle(120, 15, 80, 80, { roughness: 2.8, fill: 'blue' });<br>rc.rectangle(220, 15, 80, 80, { bowing: 6, stroke: 'green', strokeWidth: 3 });<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">SVG Paths<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/roughjs.com\/images\/m5.png\" alt=\"Rough.js rectangle\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>rc.path('M80 80 A 45 45, 0, 0, 0, 125 125 L 125 80 Z', { fill: 'green' });<br>rc.path('M230 80 A 45 45, 0, 1, 0, 275 125 L 275 80 Z', { fill: 'purple' });<br>rc.path('M80 230 A 45 45, 0, 0, 1, 125 275 L 125 230 Z', { fill: 'red' });<br>rc.path('M230 230 A 45 45, 0, 1, 1, 275 275 L 275 230 Z', { fill: 'blue' });<\/code><\/pre>\n\n\n\n<p>SVG Path with simplification:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/roughjs.com\/images\/m9.png\" alt=\"Rough.js rectangle\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/roughjs.com\/images\/m10.png\" alt=\"Rough.js rectangle\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Examples<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/roughjs.com\/images\/m6.png\" alt=\"Rough.js map\"\/><\/figure>\n\n\n\n<p><a href=\"https:\/\/github.com\/rough-stuff\/rough\/wiki\/Examples\">View examples here<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">API &amp; Documentation<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/rough-stuff\/rough\/wiki\">Full Rough.js API<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/roughjs.com\/ Rough.js Rough.js is a small (&lt;9kB gzipped) graphics library that lets you draw in a 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.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[109,45],"tags":[233,101,279,626],"acf":[],"_links":{"self":[{"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/posts\/13984"}],"collection":[{"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/comments?post=13984"}],"version-history":[{"count":2,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/posts\/13984\/revisions"}],"predecessor-version":[{"id":13986,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/posts\/13984\/revisions\/13986"}],"wp:attachment":[{"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/media?parent=13984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/categories?post=13984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/tags?post=13984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}