Tools for experimenting w/ tilings and optical illusions?

"Please leave a message at the beep, we will get back to you when your support contract expires."

Moderators: phlip, Moderators General, Prelates

User avatar
Envelope Generator
Posts: 582
Joined: Sat Mar 03, 2012 8:07 am UTC
Location: pareidolia

Tools for experimenting w/ tilings and optical illusions?

Postby Envelope Generator » Fri Jun 13, 2014 5:30 pm UTC

What FOSS graphical software or programming environment would you recommend for creating geometric art? What do people use to eg. render Penrose tilings or optical illusions involving rotational or grid symmetries?
I'm going to step off the LEM now... here we are, Pismo Beach and all the clams we can eat

eSOANEM wrote:If Fonzie's on the order of 100 zeptokelvin, I think he has bigger problems than difracting through doors.

User avatar
PM 2Ring
Posts: 3715
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: Tools for experimenting w/ tilings and optical illusions

Postby PM 2Ring » Sat Jun 14, 2014 8:07 am UTC

I assume you mean that you want to write your own custom software to generate these images. What languages do you know?

I prefer to do geometrical drawings using some form of vector graphics, partly because they scale well, but also because rotation is generally very easy in vector graphics systems.

I learned the rudiments of PostScript programming many years ago, so I often write simple geometrical stuff directly in PostScript, or write a Python script to generate PostScript code. It's easy to use free tools from the Ghostscript project to render a PostScript file to screen or to convert it to PDF or a bunch of bitmap formats; ImageMagick / GraphicsMagick can also handle PostScript.

OTOH, the modern graphics libraries I've looked at come equipped with a bunch of vector-oriented functions that look like they were mostly inspired by the PostScript primitives, even if they do do their actual rendering in bitmaps. Cairo is pretty cool because you can choose to render to a variety of contexts, both bitmap and vector-oriented.

PostScript has been around for decades, and so it's very stable and there's plenty of info available on how to use it. Of course, the computing world has evolved quite a bit since PostScript was first developed, so in various ways it's showing its age. Also, it uses Reverse Polish Notation, which some people find a bit confusing, although some of us enjoy it. :)

As an alternative to a PostScript-oriented approach, you may want to look at the SVG Scalable Vector Graphics file format, an XML format developed by the W3C. SVG is very portable: all modern Web browsers can display SVG files, so you don't need a separate renderer program. I'm certainly no SVG expert, but I've used it a little bit, mostly by creating simple SVG files using Python. SVG can do everything that PostScript can do, and more, but you can do useful stuff with it without having to learn about all of its capabilities.

Do you know JavaScript? If so, you should check out the HTML5 Canvas element, which all modern browsers support. The Canvas graphics facilities are quite good, and it's pretty easy to do either bitmap-oriented or vector stuff in the Canvas. And because your Canvas graphics are happening on a Web page, you have all the standard HTML input controls if you want to build a user interface to parametrize your drawing.

Here's a simple example I wrote a few years ago when I first learned about Canvas. Please note that this script is not a great example of JavaScript programming; my JavaScript has improved a little since I wrote it. :)

Code: Select all

<!DOCTYPE html>
<html>
<head>
    <title>Caustic curves</title>
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <style type="text/css">
        h4 { text-align: center; color: #2200aa; }
        canvas { float: left; margin-left: 5%; margin-right: 5%; }
    </style>
    <script>
        var canvas, ctx, ox, oy, rad, xt, yt, pi2 = 2 * Math.PI,
            npoints = 367, mult = 2, trans = 0.2,
            colourf = true, clearf = true, rimf = true;

        function byID(id) { return document.getElementById(id); }

        function init()
        {
            canvas = byID('canvas');
            if (!canvas.getContext)
                return alert("Sorry, I can't set up the canvas!");
            ctx = canvas.getContext('2d');

            //Get window height & calculate canvas dimensions
            canvas.width =
            canvas.height = 4 * Math.floor(0.23 * window.innerHeight);
            ox = oy = canvas.width / 2;
            rad = Math.floor(0.975 * oy);

            //Set form defaults
            byID('Points').value = npoints;
            byID('Multiplier').value = mult;
            byID('Transparency').value = trans;
            byID('DoColour').checked = colourf;
            byID('Clear').checked = clearf;
            byID('DoRim').checked = rimf;

            trig(); draw();
        }

        //Make trig tables
        function trig()
        {
            var n, t, dt = pi2 / npoints;

            xt = new Array(npoints);
            yt = new Array(npoints);

            for (t = n = 0; n < npoints; n++, t += dt)
            {
                xt[n] = ox + rad * Math.cos(t);
                yt[n] = oy + rad * Math.sin(t);
            }
        }

        function draw()
        {
            var h, n, m;

            ctx.globalAlpha=trans;
            ctx.strokeStyle = "#000";

            if (clearf)
                ctx.clearRect(0, 0, canvas.width, canvas.height);

            if(rimf)
            {
                //Draw circle
                ctx.beginPath();
                ctx.arc(ox, oy, rad, 0, pi2, false);
                ctx.stroke();
            }

            //Draw lines that create caustic envelope
            for (n = 0; n < npoints; n++)
            {
                m = (n * mult) % npoints;

                if(colourf)
                {
                    h = Math.floor(360 * n / npoints);
                    ctx.strokeStyle = "hsl(" + h + ",100%, 50%)";
                }

                ctx.beginPath();
                ctx.moveTo(xt[n], yt[n]);
                ctx.lineTo(xt[m], yt[m]);
                ctx.stroke();
            }
        }
    </script>
</head>
<body onload="init();">
    <h4>Caustic Curves</h4>
    <canvas id="canvas">
        If you can read this, your browser does not support the HTML5 Canvas.
    </canvas>
    <form onsubmit="return false;">
        Points <input type="text" id="Points" size=6
        onchange="npoints=this.value; trig();">

        Multiplier <input type="text" id="Multiplier" size=6
        onchange="mult=this.value;"> <br>

        Colour <input type="checkbox" id="DoColour"
        onchange="colourf=this.checked;">

        Transparency <input type="text" id="Transparency" size=6
        onchange="trans=this.value;"> <br>

        Clear <input type="checkbox" id="Clear"
        onchange="clearf=this.checked;">

        Draw Rim <input type="checkbox" id="DoRim"
        onchange="rimf=this.checked;">

        <input type="button" value="Draw" onclick="draw();">
    </form>
</body>
</html>


Both SVG and Canvas are suitable for animations as well as static drawings, which is a major advantage over (standard) PostScript. I've done some Canvas animation, but I haven't looked into the SVG animation facilities.

User avatar
Dthen
Still hasn't told us what comes after D
Posts: 553
Joined: Sat Jan 02, 2010 6:35 pm UTC
Location: Ayrshire, Scotland

Re: Tools for experimenting w/ tilings and optical illusions

Postby Dthen » Sat Jun 14, 2014 10:07 am UTC

I will admit to only really reading the words "geometric art" in your post before hitting reply, so this is probably not what you're looking for, but you should check it out anyway because it's awesome.
Dthen wrote:I AM NOT A CAT.

User avatar
Envelope Generator
Posts: 582
Joined: Sat Mar 03, 2012 8:07 am UTC
Location: pareidolia

Re: Tools for experimenting w/ tilings and optical illusions

Postby Envelope Generator » Sat Jun 14, 2014 11:29 am UTC

PM 2Ring wrote:I assume you mean that you want to write your own custom software to generate these images.


That's just what I don't want to do unless there's nothing already out there... and I ran into Context Free Art which looks fairly expressive if not too hands-on. They even have user-contributed implementations for the wallpaper groups.

But I imagine a graphical interface where, as the user draws, the program fills the surrounding canvas in real time based on a transformation/tiling rule of some kind. Does anyone know of such a gadget?

Thanks for the Whorld tip too! Video synthesis is another thing I've been curious about.
I'm going to step off the LEM now... here we are, Pismo Beach and all the clams we can eat

eSOANEM wrote:If Fonzie's on the order of 100 zeptokelvin, I think he has bigger problems than difracting through doors.

User avatar
PM 2Ring
Posts: 3715
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: Tools for experimenting w/ tilings and optical illusions

Postby PM 2Ring » Sun Jun 15, 2014 5:47 am UTC

Envelope Generator wrote:
PM 2Ring wrote:I assume you mean that you want to write your own custom software to generate these images.


That's just what I don't want to do unless there's nothing already out there... and I ran into Context Free Art which looks fairly expressive if not too hands-on. They even have user-contributed implementations for the wallpaper groups.


Oh well. Hopefully all that stuff I wrote earlier will be of use to somebody who reads this thread. :)

That Context Free Art looks interesting. And I imagine the learning curve for the drawing grammar would be easier than to learn how to program in PostScript, etc.

Envelope Generator wrote:But I imagine a graphical interface where, as the user draws, the program fills the surrounding canvas in real time based on a transformation/tiling rule of some kind. Does anyone know of such a gadget?

The old Amiga program Deluxe Paint had support for drawing with real-time tile and rotation symmetry. I don't know of a recent program that specialises in that sort of thing, but I guess it'd be easy enough to add to a drawing / painting program that has macro support. * does quick Google search * It appears that someone is working on a Gimp plugin that does some symmetry stuff - see GIMP is getting symmetric painting mode.

But I still reckon it'd be fun to make a program to do this sort of thing in JavaScript. :)


Return to “The Help Desk”

Who is online

Users browsing this forum: No registered users and 3 guests