SFML - Simple Fractal Markup Language
A formulation of Mandelbrot and Julia set as XML 1.0
An implementation as an XSL transform
My recommendations 21 April 2008, never revised
- This version:
- http://mzlair.se/xslfractal.php
- Authors:
- Marcus Vesterlund
Abstract
This specification defines a markup of the Mandelbrot and Julia sets. It is not to be taken seriously, and where done only to test the functional capabilities of XSL transforms. It will not deal with with the mathematics behind these fractals.
A simple example
The following markup will generate a simple Mandelbrot fractal image in html:
<p><fr:fractal xmlns:fr="http://mzlair.se/xslfractal.php"> <tt><fr:for-imaginary from="-1" to="1" steps="20"> <fr:for-real from="-2" to="1" steps="40"> <fr:mandelbrot iteration-limit="32"> <fr:infinite-color> </fr:infinite-color> <fr:color>X</fr:color> </fr:mandelbrot> </fr:for-real> <br/> </fr:for-imaginary></tt> </fr:fractal></p>
This this is the result of the fractal code as rendered by the browser:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX X XXXXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXX XXXXXXXXXXXXXXXXXX XXXXXXXX XXXXXXXXXXXX X XXXXXXXX XXXXXXXXXXX XXXXXXXX XXXXXXXXX XXXXXXXXXXX XXXXXXXX XXXXXXXXXXXX X XXXXXXXX XXXXXXXXXXXXXXXXXX XXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXX XXXXXXXXXXXXXXXXXXXX X XXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The principle
The fractal is generated by selecting and copying user defined XML nodes based on the results of the fractal calculations.
Definitions
- Color:
- Is here used as a more loosely term for coupling the iteration value with output. Normally when rendering these fractals, a color is selected based on the number of iterations which is needed for the Mandelbrot calculations. That color is then used for plotting a pixel on the screen. In this case it is used for the XML content which is outputted depending on the number of iterations. It can for example be a table cell with a particular background color or a specific character.
Tags
All tags are defined withing the http://mzlair.se/xslfractal.php namespace.
- fractal:
- This is the outer most tag which makes sure we are in a fractal context. It does not take any parameters.
- for-imaginary:
- This is the imaginary iterator tag. It iterates steps number of times. Each time making a copy of its context while iterating over the imaginary numbers defined by to and from. The number in to is not inclusive. Must include all parameters: to, from and steps. The order of for-imaginary and for-real is not important.
- for-real:
- This is the real number iterator tag. It iterates steps number of times. Each time making a copy of its context while iterating over the real numbers defined by to and from. The number in to is not inclusive. Must include all parameters: to, from and steps. The order of for-imaginary and for-real is not important.
- mandelbrot
- This is the Mandelbrot function. It takes the iteration-limit parameter, and outputs the content of child element infinite-color or the content of any of the color children. infinite-color is selected when the iteration-limit is reached. Which color element is selected is based on #iterations mod #children.
- julia
- This is the Julia function. It takes the iteration-limit parameter in addition to the imaginary and the real parameter. It outputs the content of child element infinite-color or the content of any of the color children. infinite-color is selected when the iteration-limit is reached. Which color element is selected is based on #iterations mod #children.
- infinite-color
- This contains the output when the when the iteration-limit is reached. One and only one per fractal function.
- color
- This contains the output when the when the iteration-limit has not been reached. Which color element is selected is based on #iterations mod #children.
Usage of XSL implementation
Just include <?xml-stylesheet type="text/xsl" href="fractal.xsl"?> in your XHTML file.
Appendix
Live example
Source
License
The XSL source is under the WTFPL - Do What The Fuck You Want To Public License.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2004 Sam Hocevar 14 rue de Plaisance, 75014 Paris, France Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. You just DO WHAT THE FUCK YOU WANT TO.