paperjs / paper.js

The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas. Created by @lehni & @puckey
http://paperjs.org
Other
14.5k stars 1.23k forks source link

Can I use paperjs without Browser and Nodejs environments #1903

Open jameszhong2008 opened 3 years ago

jameszhong2008 commented 3 years ago

Hello @lehni and to whom have some ideas. I use paper in several projects and it works great, I use it in Browser or Nodejs environments before. But a new issue occured, i need to use Path, Segments features in environments, neither Browser or Nodejs. I don't need to draw it on Canvas or do any other operation. Only need to process the Path's data and do some mathmatic calculation. Is it possible and how can I acheive it? Thanks a lot.

sasensi commented 3 years ago

Hello, could you tell us what environment you would want to use Paper.js into for example ?

jameszhong2008 commented 3 years ago

Hello @sasensi, Thanks for your reply. It is a Evironment called MiniProgram in WeChat, it based on browser kernel, but it did't expose window and document object. https://developers.weixin.qq.com/miniprogram/en/dev/framework/

So we can't import paperjs, because self is null here, and it is not a node exvironment. So it does not work.

self = self || require('./node/self.js'); var window = self.window, document = self.document;

But MiniProgram did expose the Canvas object. We can use it to access drawing context.

var context = canvas.getContext('2d'); var gl = canvas.getContext('webgl');

Any suggestion?