Archive for the ‘lxlang’ tag
Ray tracing, Patterns, and the Web
(Caveat before I even say anything else: the ray tracer is unoptimized and really stresses the browser’s Javascript implementation. I recommend using Google Chrome for viewing it as Chrome is notably faster at the moment…)
I managed to reorganize the Javascript-based ray tracer such that it can be used as a JQuery plug-in: transform any CANVAS element into a ray traced scene. I then incorporated the 2D patterns library I’ve been working on for LxLang into the page. The result? An HTML page with multiple embedded ray tracers, rendering the various 2D procedural patterns onto a ray traced sphere. It’s really exciting seeing all these technologies working together.
Next up, I might work on using the HTML5 File API to add some image caching – the page load time for the below is a bit ridiculous.
Click here to view the ray tracing page. Or click the image below to get a static image of the results (admittedly, a much faster approach).
Ray Tracer Update
Further progress on the Javascript ray tracer…
The patterns library, written in LxLang and translated to Javascript, is now used as well as a new mappers library written in LxLang (dynamically translated until it is developed further).
LxLang Patterns Library
I’ve been doing a fair amount of work on the patterns lately. Admittedly, the page has only been tested with Chrome and I know there are a couple issues with Firefox but, for a prototype, this is fine.
Patterns Library
Several features I’ve added recently:
- Vertical scroll bar for manipulating pattern rotation
- Link to downloadable PNG of dynamically generated pattern image
- Converted all patterns to use LxLang (i.e. GLSL-like language) and dynamically generate the Javascript
- Integrated links to Google Closure Compiler optimized versions of dynamically generated JS
- Add UI settings to control resolution and multisampling
- Added several new patterns
Providing a Link to Generated Javascript
I’m working on LxLang a GLSL-like language that can be translated to Javascript, C++, and GLSL. The motivation is to avoid maintaining the same basic, low-level graphics functions in three different languages. The translator itself is written in Javascript, so the LxLang -> Javascript translation can occur live in a web page. However, I also wanted to provide a link to the translated source as a sort of “compiled” version, since I highly suspect anyone other than myself would be more willing to use the JS code than code written in some language they’ve never heard of.
Enter Data URI, a way to provide a link to that generated source without having to ever save it to a file. I’ve use this scheme before with the extremely nice toDataUrl method of the HTML5 CANVAS element as a way to generate downloadable PNGs from dynamically generated CANVAS graphics. So: I should be able to do this with generated javascript…
Data URI for Text
The solution I’m using is quite simple. Call Javascript escape on the source text, add a “data:text/plan,” prefix, and set that as the URL. Done.
var dataUri = 'data:text/plain,' + escape(source); $("#download-link").attr("href", dataUri);
The one downside that I haven’t been able to work past yet is that Chrome disables the “Save as…” option when you visit the resulting page. I don’t understand this. To download the file, you need to right-click save the link rather than visit the page and save that. Strange.



