From b1858930ce79909d67904d417ad6be406215934c Mon Sep 17 00:00:00 2001 From: Quinten Clause Date: Sun, 11 Aug 2024 15:47:32 +0200 Subject: [PATCH] test gear --- demos/navbutton/index.js | 3 ++- img/gear.svg | 27 +++++++++++++++++++++++++++ js/draw/path.js | 6 +++++- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 img/gear.svg diff --git a/demos/navbutton/index.js b/demos/navbutton/index.js index 8e5d356..dfb90b0 100644 --- a/demos/navbutton/index.js +++ b/demos/navbutton/index.js @@ -7,8 +7,9 @@ gg.emit('color', { bg: 'navy', fill: 'white' }); gg.on('draw', ft({text: 'WIP: /js/draw/path.js'}).draw); let navbutton = path({ - url: new URL('../../img/nav.svg', import.meta.url), + url: new URL('../../img/gear.svg', import.meta.url), //paths: ['M 0 0 L 1024 0 L 1024 1024 L 0 1024 Z'], + fills: ['red', 'orange','yellow'], w: 100, h: 100 }); diff --git a/img/gear.svg b/img/gear.svg new file mode 100644 index 0000000..17f3f7b --- /dev/null +++ b/img/gear.svg @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + diff --git a/js/draw/path.js b/js/draw/path.js index 974907f..bab5353 100644 --- a/js/draw/path.js +++ b/js/draw/path.js @@ -6,6 +6,7 @@ export default (options = {}) => { let defaults = { url: false, paths: [], + fills: [], x: 0, y: 0, w: 512, @@ -16,7 +17,7 @@ export default (options = {}) => { Object.assign(options, defaults); options.draw = e => { let { ctx } = e; - let { paths, x, y, w, h, a } = options; + let { paths, fills, x, y, w, h, a } = options; let rad = a * Math.PI / 180; let cx = w / ow; let cy = h / oh; @@ -35,6 +36,9 @@ export default (options = {}) => { let np = new Path2D(); np.addPath(new Path2D(path), n); p.addPath(np, m); + if (fills[i]) { + ctx.fillStyle = fills[i]; + } ctx.fill(p); }); };