susam / fxyt

Tiny, esoteric, stack-based, postfix, canvas colouring language with only 36 simple commands
https://susam.net/fxyt.html
MIT License
117 stars 4 forks source link

More examples! #4

Closed ncw closed 1 month ago

ncw commented 7 months ago

It would be nice to see some more examples - maybe you could make a gallery of them?

This would be my submission - a very low res mandlebrot set plotter. It can only look to depth 7 otherwise it uses more than 1000 iterations.

NNNN7[SDD*N1024/RDD*N1024/R+N4096<[RN1+RR]SDD*N1024/RDD*N1024/R+N4096<![PPN4000N4000]SDD*N1024/RDD*N1024/RS-XN128-N12*N512-+RR*N512/YN128-N12*+]PPN30*

https://susam.net/fxyt.html#NNNN7bSDDpN1024qRDDpN1024qRsN4096lbRN1sRRcSDDpN1024qRDDpN1024qRsN4096libPPN4000N4000cSDDpN1024qRDDpN1024qRSdXN128dN12pN512dsRRpN512qYN128dN12pscPPN30p

That was a fun diversion for a Saturday afternoon - thank you!

susam commented 7 months ago

Great idea! Thanks for suggesting and thanks for the wonderful demo too. I have added a file demo.md to collect community demos. This file is now linked to from the main README too.

mccartney commented 7 months ago

https://github.com/susam/fxyt/blob/main/demo.md#dynamic-demos seems to be a broken link.

mccartney commented 7 months ago

Some very basic monochrome, static examples:

susam commented 7 months ago

@mccartney: https://github.com/susam/fxyt/blob/main/demo.md#dynamic-demos seems to be a broken link.

Sorry, that was a copy-paste error due to copying the file demo.md from another similar project named CFRS[] (i.e., demo.md of CFRS[]).

Fixed it in commit ea59f31. Thanks for reporting the broken link.

susam commented 7 months ago

@mccartney: Some very basic monochrome, static examples:

  • a rectangular grid
XN15%0N0=YN15%0N0=|00
  • a circle
XN128-XN128-*YN128-YN128-*+N128/N64<00
  • a filled square
XN99>XN157<&YN99>&YN157<&N255*
  • an empty square
XN100=XN156=|YN100=YN156=||XN99>&XN157<&YN99>&YN157<&N255*
  • a right triangle
XY-N0=YN50=|CXN206=|XN49>&XN207<&YN49>YN206<&&00

The new demo examples have been added to https://github.com/susam/fxyt/blob/main/demo.md. Thank you!

ncw commented 7 months ago

Here is an animated sine wave!

XT+N128-N3142*N128/DN3142>[N6284-]DN1571>[N3142S-]DNN1571-<[NN3142-S-]DDN166SD*N120000/-SD*N1000/*N1000/N1000S-*N1000/N1100+N3*N25/Y>NS[PN255]

Its very slow!

It works by using 3 terms of the taylor series for sine to calculate sine with some trig reduction rules. It uses fixed point arithmetic with a multiplier of 1000 so you can see the magic numbers 3142 (pi) 6248 (2*pi) and 1571 (pi/2) in there.

I re-arranged the calculation using Horner's method to make it more efficient.

There are probably better approximations out there with the same multiplication budget though.

PS Is there any technical reason why the links shouldn't work for > 64 characters? I don't seem to be able to get any of my examples under 64 bytes!

susam commented 7 months ago

@ncw This is another great demo! Thanks for sharing.

The 64 character code limit for distributable links has been inherited from another similar project of mine called CFRS[]. In that project, a larger code length allows drawing possibly offensive or undesirable messages on the canvas and sharing direct link to it to others. I am usually cautious about rendering content embedded in the URL directly on the canvas for reasons I have explained in my blog post Against URL-Based Content Rendering.

I am not certain if such an aggressive limit is required for this project (FXYT) too. I see that it takes me about 50 to 100 characters of code to draw a single tiny lowercase English letter on the canvas, so I am hoping a limit of 64 characters would allow the perpetrator to draw at most 1 or 2 letters on the canvas. With 256 characters of code allowed in distributable links, I am worried it could allow the perpetrator to draw about 3 to 5 letters on the canvas and that is getting close to the limit of my comfort level.

I know this limitation is a significant impediment to sharing direct links to impressive demos! But as a result of having sunk a lot of my leisure time filtering out bad content in other web-based projects of mine, as outlined in the aforementioned blog post, I tend to err on the side of caution these days.

susam commented 7 months ago

@ncw By the way I am a happy user of Rclone! So it is very nice to have you here! Thank you for all the work you do on Rclone!

ncw commented 7 months ago

@susam I hadn't thought of the potential for malicious use and I totally understand where you are coming from as in a previous job the company used to run a free web hosting service!

It would be nice to make the limit a bit longer, but happy to go with what you decide.

Playing with FXYT has been a nice distraction. The constraints make it challenging and the stack based language reminds me of FORTH programming which I haver a soft spot for! It seems perfectly designed for running on a GPU. I suspect you could translate it to a shader quite easily. (Maybe it does that already - I didn't peek at the source yet!)

Glad rclone is working for you - always nice to hear from happy users 😃

susam commented 7 months ago

@ncw: Here is an animated sine wave!

XT+N128-N3142*N128/DN3142>[N6284-]DN1571>[N3142S-]DNN1571-<[NN3142-S-]DDN166SD*N120000/-SD*N1000/*N1000/N1000S-*N1000/N1100+N3*N25/Y>NS[PN255]

Its very slow!

It works by using 3 terms of the taylor series for sine to calculate sine with some trig reduction rules. It uses fixed point arithmetic with a multiplier of 1000 so you can see the magic numbers 3142 (pi) 6248 (2*pi) and 1571 (pi/2) in there.

I re-arranged the calculation using Horner's method to make it more efficient.

There are probably better approximations out there with the same multiplication budget though.

PS Is there any technical reason why the links shouldn't work for > 64 characters? I don't seem to be able to get any of my examples under 64 bytes!

Added this demo to https://github.com/susam/fxyt/blob/main/demo.md#animated-sine-wave. Thank you!