-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Allow color computations in MathFormula and use to allow computed Turtle colors #530
base: ui2
Are you sure you want to change the base?
Conversation
OK, this now picks up where #528 left off. You can now switch back and forth to the formula display of Turtle parameters, but the formula parameters do not yet have any effect. I will continue the implementation and mark as ready for review when I think all is well, but welcome feedback now or at any point. |
OK, added a colorChooser that will insert into whichever color parameter is currently in effect. The formula parameters are still not implemented. |
Now the list rules convert themselves into formulas whenever they are entered, but Turtle still only draws using the list rules. Also, all of the checks should now pass (at least when run locally). This way, I can switch over to always using the formulas for drawing and make sure that I get exactly the same images. |
OK, Turtle is computing with formulas for all the attributes of each segment: turn, step, width, and color. When you are in List mode and you change the list parameters, it updates all of the formulas to be ones that implement the list rules. I suspect I need to update the Github snapshots, but this can be reviewed in the meantime. And it could really use a Turtle example that actually uses one or more of the formulas in a meaningful way, so Kate if you have or can cook up one or more such example(s), please push a commit that adds it/them Note that the translated formulas for the list rules are pretty klunky; they are done in a way to hopefully work in all circumstances. If you just want the turn angle to be 30 degrees times the sequence value mod 5, for example, you can write |
OK, snapshots updated. All differences were just font/text layout. So the new Turtle is reproducing the old one, while extending it to allow formulas. As far as I am concerned, this just needs a commit with a Featured specimen (or more) that uses formulas, with at least one color formula involved, and the usual review of the PR itself. |
We had a sort of "group review" in meeting today, and it generated the following TODO items; I will mark this PR as draft until they have been implemented:
I am not planning to make any other comments as/when I simply push a commit that implements one or more of the above, but I will check the items off as I do, and mark this again as ready for review when they are all done. |
This produces a disconnected path. This is perhaps a malformed URL in some sense, as it includes both List and Formula mode parameters. To reproduce from first principles, open Wait For It, then go to Formula mode. Change the formula entries to a, a, 1, white; then change the sequence formula to xgcd(3,n)[2]. The resulting path is disconnected, but as far as I can tell from the choices "a,a,1,white" it shouldn't be possible? |
I'm trying to do things like 'chroma.scale()(0.5)' in the colour formula but it doesn't work. |
And this is convergence of the first Riemann zero (approximately....) http://localhost:5173/?name=Convergence+of+the+first+Riemann+zero&viz=Turtle&speed=10&ruleMode=1&turnFormula=log%28n%29*14.134725*360%2F2%2Fpi&stepFormula=200%2Fsqrt%28n%29&colorFormula=chroma%28%27skyblue%27%29.set%28%27hsl.h%27%2C+a%25360%29&seq=Formula&first=10 |
If you look at the warning
you can get some clue as to what is going on: mathjs is parsing this formula, not entirely unreasonably, as multiplying the result of calling you can work around this with various ridiculous exotic expressions that enforce the function call interpretation; one that works right now is Incidentally, Jos has recovered enough to merge the bigint bugfixes, so I am returning for a bit to the effort to update mathjs in numberscope to a version that supports bigints. So that will give some time to mull over this scale() operation. |
Thanks for the explanation! Among the options here, I prefer the double parens, because space is at a premium in these little dialogs. There's another thing that doesn't work but should, I believe: |
Actually, there's an even better alternative, I think, that doesn't yet work but that I am proposing for mathjs and that we could pre-implement here: I will check out the |
Oh that seems like a very nice solution. |
Re chroma.brewer, it's a whole different issue: mathjs has a ban on property access of imported objects that are not "plain objects" (i.e. have a constructor other than the default Object constructor), although it does allow method access (like So we need to work around this in our particular case -- there's not going to be any change at the mathjs level relevant to this, at least not in the foreseeable future. So we could either:
I am fairly agnostic as to which way to go among these three, so if you have a preference, let me know. |
I'm inclined to shorten things, if they have to change from the chroma docs anyway, so (2) is appealing in that sense. But first, is it the same issue with |
OK, I will add that to the TODOs.
Nope. That was because mathjs by default uses a fancy Matrix type to interpret the expression
It already does, just look at |
P.S. I am again mostly preoccupied with mathjs bigint shortcomings so we definitely won't clash if you happen to add tests any time in the next couple days. |
Done! I've added pretty much all the constructor types by working through the docs. The thing you said was fixed doesn't pass, btw, not sure why (it works in the browser). But anyway there are a number of skipped tests there. |
Another thing I just came across. Go to the following URL with no saved sequences: and then click to change the sequence. Popups occur about complex numbers. I'm guessing it's the turn formula that is a problem, combined with the xgcd and array call in math.js. But these errors aren't getting caught, they are breaking through to pop-up. If you change the xgcd formula to random (both positive and negative), no problem. If you change the turn formula to reference n instead of a, no problem. |
OK, I've added these anomalies to the to-do list. |
By submitting this PR, I am indicating to the Numberscope maintainers that I have read and understood the contributing guidelines and that this PR follows those guidelines to the best of my knowledge. I have also read the pull request checklist and followed the instructions therein.
This is a reconstituted version of #528. It incorporates the color computations of chroma.js into mathjs and allows them to be used in MathFormulas to compute colors. It then uses this facility to allow the stroke color (and all other segment parameters of Turtle) to be computed by formula.
With the more complicated options for the Turtle parameters, it also adopts the changes to ParamField and ParamEditor layout from the first three commits of #522.