hhenrichsen / canvas-commons

Hunter's Motion Canvas Utilities
MIT License
27 stars 1 forks source link

Plotting algorithm #14

Open spidunno opened 1 week ago

spidunno commented 1 week ago

Currently, LinePlot just samples the function at a bunch of evenly spaced points, but much higher quality results could be obtained through an actual plotting algorithm where more points are sampled where the function changes rapidly. I believe it's called adaptive function plotting.

Also, plots of implicits would be cool, if you need a library for that you can use a typescript port I made of a python one https://npmjs.org/isosurfaces

hhenrichsen commented 1 week ago

Yeah, there's been some similar discussion of the best ways to do this on the Motion Canvas Discord server (why I remember this conversation from a year and a half ago, I can't say). I'm not opposed to PRs that make it better; I provided a default implementation that samples so that other options could be provided, but the LinePlot really just needs (and takes) X-Y pairs. The sampling approach worked for what I needed at the time, so I didn't feel the need to chase what was ultimately yet another rabbit hole.

This is also quite a ways out of my background, so while I could learn it myself, I'm sure someone with the background could implement it much better (and likely faster). I'll leave this open if someone wants to open a PR for it, but it's not an immediate priority for me so it's unlikely either better sampling or implicit plots will happen on their own.