Seamless interoperation with the DOM ==================================== Practical example: a simple, responsive website using no HTML or CSS at all --------------------------------------------------------------------------- To many programmers, using 'static' HTML and CSS feels like being locked up in a closet. As an alternative, responsiveness can simply be programmed using Transcrypt, as can be seen on `the website of Transcrypt itself `_. The site adapts to diverse screen formats, device types and landscape vs. portrait mode. SVG example: Turtle graphics ---------------------------- *Turtle graphics* are a way to teach computer programming to children, invented by Seymour Papert in the 1960's. Lines are drawn as 'track' of a walking turtle, that can move ahead and turn. Children use turtle graphics intuitively by imagining what they would do if they were the turtle. This leads to a *recipe of motion*, indeed an *algorithm*, which is the basis of imperative (as opposed to e.g. declarative) programming. *SVG* or *Scalable Vector Graphics* are a way to display high quality graphs, e.g. in the browser. SVG, as opposed to e.g. the HTML Canvas, bypasses the pixel paradigm and works with floating point coordinates directly. As a consequence, SVG plots can be zoomed without becoming ragged or 'pixelated'. When looking under the hood of SVG, there's an amazing correspondence between the primitives in an SVG *path* and the primitives of turtle graphics. So both from an aestethical and from a conceptual point of view, turtle graphics and SVG form a happy mariage. Turtle graphics in Transcrypt do not require the use of any graphics libraries. Below are two turtle graphics examples and the source code of Transcrypt's *turtle* module, which is quite compact. As can be seen from the code integration between Transcrypt and JavaScript is trivial. .. literalinclude:: ../../demos/turtle_demos/star.py :tab-width: 4 :caption: Drawing a alternatingly floodfilled star `Click here to view the resulting zoomable star `_. .. literalinclude:: ../../demos/turtle_demos/snowflake.py :tab-width: 4 :caption: Drawing the contours of a snowflake `Click here to view the resulting zoomable snowflake `_. .. literalinclude:: ../../modules/turtle/__init__.py :tab-width: 4 :caption: Transcrypt's turtle graphics module sits directly on top of SVG, no libraries needed, so a very compact download Remark: In a later stage animation may be added. As a further step, for complicated fractals, transparent server side compilation of a relatively simple algorithm would allow on-line editing combined with fast client side rendering of high-resolution graphics. Mixed examples ============== Example: Pong ------------- In using the fabric.js JavaScript library this for example, the only thing differing from plain JavaScript is that *new * is replaced by *__new__ ()*. .. _code_pong: +----------------------------------------------+---------------------------------------------------------+ | .. literalinclude:: ../../demos/pong/pong.py | .. literalinclude:: ../../demos/pong/__target__/pong.js | | :tab-width: 4 | :tab-width: 4 | | :caption: pong.py | :caption: pong.js | +----------------------------------------------+---------------------------------------------------------+ Four ways of integration with JavaScript libraries ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ There are four ways to integrate Transcrypt applications with existing JavaScript libraries. 1. The simplest way is to use the library as is, without any encapsulation. In this way all symbols of that library will be in the global namespace. While many JavaScript programmers don't seem to mind that, many Python programmers do. For example, in the Terminal demo, the JavaScript module is imported using a *