Implementation notes Motion patterns. ---------------------------------------------------------------------- 0. Concept Been playing too much Touhou, what can I say. I never got tired of it. It's such an inspirational series. This time around, I was intrigued at some optical illusions that appears to move, even though the image is static. I was thinking how some of the bullets would look like if they were drawn with optical illusions in mind, and naturally Udonge's spell cards came to mind. I just have to do it. ---------------------------------------------------------------------- 1. Design Part of this project involves studying various optical illusions to see how they did it. After getting totally tripped out and making my eyes worse than before, I found that two key ingredients for achieving motion are: - Directional patterns. - Psychedelic and contrasting colors. Udonge produces directional patterns are achieved by positioning bullet-shaped sprites in a rectangular grid, then set rotations for each sprite using some sinusoids to produce a swirl-like pattern. Some tweaks were needed to get the sinusoid periods to match the sprite spacings to make the end result look decent. For the psychedelic colors, Udonge chooses two different color hues so that they are have some contrast, then interpolate from one end of the sprite to the other using HSB color model. After having implemented the initial version of Udonge, I thought I could do another one that has similar concept, so I implemented Tewi. The differences are: - Polar instead of rectangular grids. - Bullets with round edges instead of straight edges (this difference is also visible in the original game). - Simple color shades instead of psychedelic colors. So actually, Udonge and Tewi are almost completely different... ---------------------------------------------------------------------- 2. Implementation The programs are implemented in PostScript. PostScript is the language of choice for doing 2D graphics, no doubt about it. As such, I thought the implementation were fairly straightforward. Two bits that were somewhat nontrivial: - Where needed, overlapping shapes of different colors were drawn, and then trimmed using a clip path. This avoids some unpleasant artefacts at shape boundaries due to numeric precisions. - Both Udonge and Tewi supports and externally specified Seed for seeding the random number generator. Because as it turns out, it's hard to get something random using only PostScript. ---------------------------------------------------------------------- 3. Layout Having implemented the initial code, the last part is to shape it to a specified layout. This is usually the easiest and most mechanical part: in other languages, all it takes is time and patience, but PostScript... I never thought it would take this much time. Actually, Udonge didn't take all that much effort, but Tewi gave me quite a bit of grief. And Tewi was harder because she has less non-contiguous whitespace present in her image. I never thought whitespace would be such a precious resource! The problem has to do with the lexical structure of PostScript: in most other languages, most alphanumeric and punctuations characters normally would form separate tokens, but in PostScript they are not separate. You have to either use whitespaces, or some "{}exec" trick to fill in the gaps. Because I am not used to making templates that accounted for required whitespaces, Tewi took a few restarts to get right. I guess somehow it seems more fitting that it took more cunning skills to get Tewi right, while Udonge was all straightforward. Other than the whitespace bits, PostScript is an extremely obfuscator friendly language, more so than Scheme. That's the power you get to be able to mess with the stack and operator precedence directly. That, and being able to name a function "$" is just precious. ---------------------------------------------------------------------- 4. Testing For every few lines of code completed, I did these steps: - Check that the image looks reasonable in GhostView. - Paste the code into GhostScript to verify that nothing is left on the stack when the program exits. - Convert to PDF to zoom in on each shape, and check that they are still the same shape (you can't zoom in with GhostView, because every redraw would generate a new pattern). I printed only once during the development, paper and ink being a more precious resource than electricity. I think the final versions still prints with just plain "lpr", but there are probably some printers out there where this won't work. Oh well. Also, staring at these patterns all day does hurt my eyes, more so playing Touhou at Lunatic difficulty. I think it has more to do with the white background than the patterns being optical illusions. ---------------------------------------------------------------------- 5. Finally... Please publish tankoubon for "Tsuki no Inaba to Chijou no Inaba"!