2012-12-18How to change the font of the Windows console with PythonThe default font for the console on Windows is some basic raster font without much support for more exotic Unicode code points. Which kind of sucks for command line programs, if they are dealing with Unicode data and foreign languages. It is possible to change the console font to “Lucida Console”, which supports a lot more code points, or, if it is installed, to “Consolas”, which supports even more code points, by clicking on the icon in the upper left corner of the console and choosing to change the properties. But we can’t seriously expect the user of a script to go through the trouble of changing the font of the console manually. Is it possible to change the font of the console inside a Python script running on said console? Usually, the most natural thing to do would be to look at the module win32console, but unfortunately, it doesn’t implement the needed call to SetCurrentConsoleFontEx. Too bad, but basically just a mere inconvenience, since we can always do stuff like this using the ctypes module (with the additional bonus that since Python 2.5, ctypes is part of the Standard Library, so we don’t have to rely on the availability of an external library). The following code shows how it is done: …
2012-08-12Using Adobe Open Type Fonts Ornaments In XeTeXOnce upon a time, ornaments, dingbats, flourishes, symbols and other embellishments were put in special pi fonts, with the symbols mapped to ordinary letters. For example, in Zapfino Extra Ornaments, you could type a capital letter X and get a nice flourish, which had nothing at all to do with the letter X. With the advent of Open Type and Unicode, some symbols where put in the Private Use Area of Unicode. For example, Adobe Garamond Pro has three flourishes at the code points U+E09D, U+E09E and U+E09F. That’s a lot betters, since it avoids semantic clashes (don’t confuse search engines and other bots by typing an “X” if you don’t mean “X”), and it also degrades more gracefully if the intended font isn’t available (in which a “can’t print this” symbol is a better choice than the rather misleading letter “X”). Still, it is far from perfect, since it turns the Private Use Area into some kind of font-vendor-specific swamp devoid of any interoperability and meaning. After all, any information about what U+E09D means is lost, since it could be an ornament, a symbol (with a rather specific meaning), some rare ligature or some other typographical feature like a subscript or a small capital. So an even better approach would be to interpret ornaments as some kind of stylistic variation of a default ornament, like the bullet point U+2022. A search engine or any other kind of bot would see the letter U+2022 and would know (more or less) what it is supposed to mean, and the different ornaments could be accessed as an Open Type feature. …
2012-05-15Three.js and Stella-like polyhedronsWith a framework like Three.js, it is pretty easy to display the faces of simple polyhedrons using WebGL. But a polyhedron, considered less as a physical and more as a topological object, consists not only of its faces. Instead often its vertices and edges are equaly interesting, and it would be nice to have an easy way to display them, perhaps assigning them different colors, to distinguish different kinds of vertices or different kinds of edges. Within the program Stella, vertices can be displayed as small balls and edges as thin tubes, and I wrote a function to be used in conjunction with Three.js which makes it a bit easier to construct similar graphical objects, following a similar visual style, within WebGL. In the following examples, I’ll assume that we have set up all the usual Three.js stuff with renderers and virtual cameras and mouse controls and lights and that we have defined a Scene-object. Furthermore, I’ll assume that we imported my helper file JAN3D.js which contains the function JAN3D.stella() (among other stuff; I also included JAN3D.TinyTrackballControls). I’ll show, using four examples, how to use this function. …
2012-04-15Making the AnaglyphWebGLRenderer a bit more protrudingThe WebGL-framework Three.js I mentioned in the previous entry has a nice variation of its renderer which renders scenes as red-cyan anaglyphs. So using Three.js, you basically get anaglyphs for free without any additional work on your part (an anaglyph is an image where you need glasses with red and cyan glasses to get a stereoscopic, three-dimensional view). I tried to construct a little scene using this ability, but what I disliked was that the scene, as an anaglyph, was too distant and appeared to be positioned behind the screen. I had a scene with several concentric circles of spheres, and I wanted them to appear to intersect the plane of the screen, with the center of the circles coinciding with the screen. And since I found no way of doing it, I plugged two new parameters into AnaglyphWebGLRenderer, called the new version ProtrudingAnaglyphWebGLRenderer and put it in a file ProtrudingAnaglyphWebGLRenderer.js. …
2012-04-15Modified TrackballControls for Three.jsWebGL is a technology that allows web browsers to display graphics using the fast routines of the graphics card, and Three.js is a framework which makes working with WebGL a lot easier. Among many other things, Three.js provides “controls”, Javascript objects which handle the interaction between mouse events and the WebGL canvas. One such control is TrackballControls. It maps mouse dragging gestures on an imaginary trackball and rotates the scene accordingly. I have used it to make models of polyhedra rotatable for my viewers: Stubsmütter und Tribanocci (a link to the German section of this blog). Per default, the imaginary Trackball fills the entire available browser window. This is less than ideal if the actual WebGL canvas is just a tiny illustration within a larger text: …
2011-11-03Mixing HTML and TeX in a StyledTextCtrl in wxPythonI have written my very own editor with syntax highlighting to write these sketches. This is far less impressive than it might appear on a first glance: wxWidgets, and therefore also wxPython, provide access to the Scintilla library via the StyledTextCtrl element, and this element can display HTML source code and style the different elements in different colors. Scintilla provides “lexers” for different languages, parsers which are able to determine which fragments of a document are keywords, identifiers, string literals, numerical literals, operators, comments and so on, and tokens from different categories can be styled differently. So “writing my own editor” in fact just means “gluing together some standard pieces”. It looks like this: …
2011-10-23The girl version of the “On the population dynamics of “Puella Magi Madoka Magica”” essayI’m not completely content with the appearance of the preceding sketch, and so I decided to try to prettify it a bit. I replaced all the equations generated by mimetex as GIF images with texts I pipe through MathJax, so if you have Javascript disabled, you’ll see all equations as \(\LaTeX\) plaintext. Furthermore, I replaced all the screencaps I took from OpenOffice or Excel and replaced them with with pretty matplotlib plots; and I also re-did all the previous matplotlib plots. And I tried to enhance the layout of the page a bit, and added more stills from the series. So this is my second take, the content remains unchanged, but I attempted to make the appearance more fitting for a series about cute girls. …
2011-10-16On the population dynamics of “Puella Magi Madoka Magica”This sketch is devoted to the population dynamics of the fictional world depicted by the Japanese animated TV series “Puella Magi Madoka Magica”. As such, it is inevitable going to reveal at least one major plot point. So if you are planning to watch this show, I suggest that you postpone reading this sketch until you are done watching it. You have been warned: there will be spoilers. …
« previous page
(Page 1 of 2, totaling 16 entries)
next page »
| QuicksearchRecent Entries
ArchivesLatest Skizzenblog Entry |