LingDong- / q5xjs

A small and fast alternative (experimental) implementation of p5.js
https://q5xjs.netlify.app/
The Unlicense
544 stars 25 forks source link

The rendered graph is lean #19

Open asukaminato0721 opened 1 year ago

asukaminato0721 commented 1 year ago

Thanks to this library, it cut the render time a lot.

https://editor.p5js.org/AsukaMinato/sketches/ftth2jRtZ

This is the newton fractal set.

By q5

image

by p5

image

Why it's not the same graph…

LingDong- commented 1 year ago

Very curious issue, thanks for reporting!

Turns out it's because q5 doesn't support subtracting a scalar from a vector (yet), so change the line from this:

const f =  (x) => vectorPow(x, 4).sub(1);

to this:

const f =  (x) => vectorPow(x, 4).sub(createVector(1,0));

Easy to add the feature. Only concerns are that: more type checking overhead; clarity: should (1,2,3) - 1 be (0,2,3) or (0,1,2)? (1,2,3)*2 is not (2,2,3). But in the spirit of compatibility with p5 we probably should support it...