Showing posts with label grammars. Show all posts
Showing posts with label grammars. Show all posts

Tuesday, March 20, 2012

Patterns, Part 4

There are some patterns that just can't fit together without some kind of grammar: patterns in how the pieces interrelate. Like grammar in language, this usually means a set of rules. And this is the way most patterns work in the real world: patterns in the interaction of people, patterns in code, patterns in mathematical rules and groups, patterns in messages. We will examine a simple grammar: the even-odd grammar, and also a much more complex grammar, with a larger set of rules.

The even-odd grammar is an easy one: imagine a checkerboard. There is one rule for the black squares, and a second rule for the white squares. Let's look at a few examples.

even
odd
The first pattern, shown above, is not obviously an even-odd pattern. But its rule set says that in even squares, we must choose from the left basis set. These have a common trait. The yellow is in the upper left and the orange is in the lower right. The priority of the elements is the other aspect, and that's what makes for two elements in the even basis. In the odd basis (right) the common trait is that orange is in the upper right and yellow is in the lower left. And they have their own priority. This set was actually an image hose in Painter originally. But here I have dissected it further and given it a grammar.

Now, we mentioned a checkerboard, which is also a pattern. This has an even rule consisting only of a black square and an odd rule consisting of only a white square. But all checkerboard-like patterns can be represented this way, for example this one.

Yes, this looks like the pattern used on non-slip metallic surfaces. You see it in industry and it is quite familiar. Like the plainweave pattern, it has a horizontal and a vertical symmetry about it, like the weft and the warp of a weaving.

The basis set for this is quite simple and ingenious.

even
odd
The even basis set consists of one image: the horizontal line. Because the lines intrude into the other square, you can see the ends of the vertical line in the horizontal piece. The odd basis set is similar, but rotated 90 degrees.

This illustrates the simplest form of even-odd pattern grammar, like the checkerboard but a little more interesting.

Now we are going to go a bit loopy. We can modify a simple plainweave grammar to include loops and such. You can see that the crossings behave in a completely entangled even-odd way, and this is enforced by the grammar we used to construct it.

My pattern program can generate these in a random fashion, but I can also draw them, using the grammar to enforce the placement of elements from my brush.

In this case, I carefully drew this one to avoid small loops and to include some knots. I was going for a particular aesthetic.

I just love loops and knots. There is a kind of secret language to them. And I guess this is what I am revealing here!

even
odd
The basis set for this contains the plainweave basis set as a subset. Then I have included some elements from my curved grammar. The common aspect to each element is that the lines meet at the center of the square edges and they all have a direction that, at the edge, becomes horizontal or vertical (orthogonal).

Just to show that we can create branching and tree-like patterns with an even-odd grammar, I have included this example. Unfortunately there are some cycles in it as well. But, all in all, a complex branching pattern exists that can branch in any direction.

Like the loopy pattern, this one has an aspect of visual complexity to it.

First, it's totally not obvious (to me) that it can be constructed from a pattern basis set. I discovered this one while playing with rendered pattern elements in my patterns application. This particular rendering is totally random.

even
odd
The basis elements are appallingly simple. They are T's. The even set has horizontal crossing and either an upwards or a downwards branch. The odd set is a 90-degree rotation of the even set, with a vertical crossing and either a leftwards or a rightwards branch. It's actually kind of clean the way it's constructed!

This pattern was one of the image hoses included with Painter 3 when it shipped. But with Use Brush Grid gone from the nozzles palette, this can't be done any more. Sad, actually.

I will leave it to you to figure out how it can be constructed as an even-odd grammar. There are two basis squares per rule, and two rules, one for even and one for odd.

This one is called the knobby pattern, by the way. It does contain some dots, and also some circular holes.

You might have noticed that there is a 45-degree tilt to many patterns that you can make with the even-odd rule. And a checkerboard becomes a regular lattice in some ways when you turn it 45 degrees.

Now let's turn to a more complex grammar. I had an idea that a lattice with square holes cut out of it in 3D could be a pattern.

Here is an example of the principle in action. You can see the square lattice and the holes cut out. Once they are cut out, the sides need to have dimension lines, giving them faux depth.

Once I drew this, I realized that there were several cases and the grammar would be complicated. In all, I counted eight possible shaded square cases, including the entirely inside and entirely outside squares. So let's look at how the elements are encoded as they are placed on a regular grid.

We can see that, to get the shaded look, we will have to tag a number to each case and allow them to be placed in a geometrically reasonable configuration.

So the real question becomes: what elements exist and what is the possible set of connections between the elements?

This means we will have to enumerate all the possible elements (8 elements as it turned out) and also enumerate all the ways the elements fit together. Of course, this turned out to be a time-consuming process. And, when it was implemented in patterns, it had a few bugs. But I am good at finding and fixing bugs in logic, fortunately!

Here you see the eight elements in schematic form and the connection diagrams that form the grammar that controls the placement and configuration of the elements.

Element 0 is the entirely inside square, and element 7 is the entirely outside square. I have used the same convention as the earlier diagram.

The left table shows what configurations are legal vertically, and the right table shows what configurations are legal horizontally.

There probably should be more obvious symmetry to the table, which might be had by reordering the numbering of the elements. But this grammar does work.

You can see a rendering from the patterns application, generated entirely by random placement and adhering to the grammar as advertised.

It definitely can achieve the proper appearance, which looks like an orthogonal shaded view of blocks with shading. Perhaps like a shaded bitmap.

So pattern grammars can be molded to solve real problems in configuration and generate looks that are interesting to our eyes.

But I have only scratched the surface, really.




Wednesday, February 1, 2012

Where Do Ideas Come From?

Sometimes I have too many ideas. The problem becomes: which ideas might pan out, and how do they interrelate? But for most, it's more a question of: where do ideas come from? Let's talk about the various places.

Spontaneous Head Combustion

Sometimes an idea just pops into your head. I think this is because brains are always processing in the background. I had a calculus teacher in high school, Mr. Pearson, who said that the solution to a particular differential equation he had been working on would sometimes come to him while shaving.

Though that was a fairly nerdy thing to say, he wasn't far off my point.

The process of spontaneous idea generation is related to why we dream: the brain always wants to exercise in periods of disuse. When shaving or driving, your brain is not fully engaged. This means there are cycles that can be put to use. We will return to this later. But some people dream in ways that are connected to stuff they are working on. During my most productive periods when I get a cool idea and then rush to implement it (especially a very complex one that will probably take several days of constant work) I am told that I sometimes talk in my sleep: I'm mumbling variables and data structures. This definitely happened to me when I was working on Mosaics in Painter.

Hmm. Maybe I work too much!

But a simple way to use this is to think about a problem before you go to sleep, and your mind may come up with a solution while you sleep. In fact, I used to listen to music in my head right when I was going to sleep. I liked to listen to Beethoven's 9th Symphony in this state. Not really listening, per se. Actually just hearing it in my mind, every note and phrase. It was great practice for musical composition.

Sketch It Up

I like to sketch things out, and get ideas that way too. I guess it's because I'm a visual person. But, for me, lots of graphical ideas work themselves out on paper. A doodle can quickly become something larger.

I was working on borders and corners one day when I realized, as many people have, that you could represent the corners as four image pieces and the edges as another four image pieces. And the edges could be stretched or repeated. So I drew one of my favorite things, and I have reproduced it at left. I suppose it's a good example of three-dimensional thinking.

I draw in guide lines that showed the corner pieces and the edge pieces succinctly. Then I realized that these corners and edges could be filled with pretty much any image.

So i drew cylinders with pipes interconnecting them, like you see at right here. I realized that even shadows could be part of these clipped images. Note: this 3 x 3 partitioning is used to create buttons and other UI elements, also. In fact, that was what I was using it for at the time.

But I didn't want the UI to be constrained to be a rectangle. No matter! These pieces will still work, as long as all the corners are squarish. For instance:

At right, I have shown something that can be made out of the usual eight pieces, just rearranged in a different fashion from the typical arrangement I have shown so far.

This goes to show that it doesn't matter how you design it. If you take a little care, that design can service a much larger class of objects.

This design really hinged on two things: the corners and the edges. So I concentrated on the corners. What could the corner possibly be? A number of three-dimensional things popped into my head, and I sketched them up.

Here are a number of possibilities that occurred to me, drawn as corners. To left: a gabled approach that exhibits shading and has pyramidal corners. To right: that same approach, but with different edges. The edges can have their own articulations as well.  There are plenty of three-dimensional things that can grace the corner of a design.

Here, I explore the use of cubes and balls. To right I considered using a stake at each corner and a taut piece of rope in between. And knots on the rope in between the corners.

Of course, there are a number of articulations on the edge that can be used in addition to knots and spikes. Really, any repeating line pattern can be employed along the edge.
Here are some line patterns: wavy lines, beads, and twisted rope. Of course braids and yarn motifs are useful as well. But plain patterns, like stripes and diagonal "candy" stripes are also useful.






Exercising Your Brain

When I am otherwise not mentally engaged, I use that time for practice. Sometimes I do something tedious like factoring five-digit numbers in my head. You know, I like prime numbers. For instance, today I passed a house on San Jose-Soquel Road that had a number of 24,769. (I look on the right side as I'm driving home and there are often odd numbers like this one, which means they won't be divisible by 2.) I'll cut to the chase and tell you that it's 17 x 31 x 47. It took me about 4 minutes to determine that, performing long division in my head. Then, when I got home, I checked it using Siri.

It may be tedious, but it does help to keep my brain sharp when it comes to numbers. Another activity I do while driving is writing songs. I compose the melody and lyrics simultaneously. When I get an idea, I record it into Voice Notes, an iPhone app. I will go over the lyrics a few times and record a verse or a refrain.

This process keeps my creativity working while I would otherwise be bored. Exercising the right side of my brain. I used to turn on the radio while driving. I don't do that any more. I let my mind fill the silence.

I also got a great idea for a novel while driving. So I used Voice Notes to get it all down.

And, by the way, it might be a good idea to pull over, if you get too involved in an idea while driving!

Know Your Subject?

When I am wracking my brain for ideas on a particular thing, I can easily come to a standstill. It is at moments such as this that I take a step back. Specifically, this is called meta-level thinking. This process can actually be impeded by knowing too much about a subject. You can get into the mindset of thinking that it's all been said and done.

When writing a novel, it can be as simple as taking a step back and considering a character's arc. When writing music, this can manifest itself as rearranging the structure. Or adding in a full break or another device that so often makes songs interesting to our ears.

The Beatles practiced this. In We Can Work It Out, for instance, there is a section that breaks into triplets in an otherwise foursquare piece. On the back side of Abbey Road, they ran all the songs together into a single homogenous piece, a structural device.  In Getting Better, one of the verses becomes one long melody instead of several broken up melodies. On All You Need Is Love, the verses contain an extra half-measure per phrase, which helps to offset the otherwise foursquare melody (the Beatles called it the Dirge), the device of changing the time signature.  Or just having two authors can create a cognitive dissonance that can make a piece remarkable. On I've Got A Feeling, arguably the last composition that Lennon and McCartney wrote together (unless you consider the back side of Abbey Road to be a single piece), their contributions are quite different, and improve the song immeasurably. It goes on and on.

When programming, it helps to look at the problem in a different way. This can be a meta-level approach when you look at multiple ways of solving the problem, or you find a way to combine what would otherwise be different methods. This is particularly good when there is something you are missing.

Sometimes it's just a matter of employing multiple modes of thought at the same time.

Ideas Travel In Groups

When finding another person that is likewise creative, it is often possible to have a huge idea session. This has happened to me countless times with various people, including Tom Hedges and John Derry, the co-authors of early Painter.

A single session can generate hundreds of good ideas, I have found. When you get onto an interesting or fruitful subject, the result can be a veritable treasure trove of ideas.

This may be the Lennon and McCartney effect: the influence of two brains on creation is synergistically better than if the two created separately.

I have experienced this effect with John Derry on several occasions. Together we thought up Painter's image hose, for instance.

Combining Expertise

When you become an expert on one subject, it can help to give you the ability to solve problems in that subject. But is thorough research a ticket to stagnation?

I have found that it helps to be an expert on several subjects and then to combine the knowledge between the subjects. I'm a pretty good programmer, for instance, and I know how to draw. Combining them produced Painter.

Anyway, it's hard to ignore the profound influence of general thinking: knowing a reasonable amount about several subjects and thinking about how they relate.

Grist For the Mill

I'm not sure why it is, but I am equally sure that this is true: when we have emotional experiences, we are driven to create. This is typified by Lord Byron clutching his forehead at the top of the stair: the tortured artist. Or by Michelangelo undergoing great pains to complete the Sistene Chapel's frescoes: the agony and the ecstasy. Is it a cliché that only through pain can we create?

No, I don't think that it is. After hitting a patch of black ice and crashing my car in Denmark on the night of December 28, 1995, I sat down and wrote 7 really good poems. Sure, I write song lyrics, but poems? I was in a rare mood that evening after some wonderful "Good Samaritan" Danes stopped to pick me up and kindly delivered me to my Hotel in Copenhagen. Note that this near-death experience is not chronicled in my post Handling Serious Events. It seems I have more than my share of such events.

But, seriously, how many love songs are there? How many my baby done left me songs are there? I tell you: there's something to this theory of emotional distress and creativity. It's grist for the mill.

Tuesday, January 24, 2012

Patterns, Part 2

Back in 1993, I tested a special capability that, unfortunately, has since disappeared. It allowed you to devise patterns that used a set of basis tiles, so that each tile could be chosen from this basis set. I call these tiling grammars.

At the right is an example of such a pattern. When I write pattern, I mean a non-repeating arrangement of items taken from a small set.

In this case, you can easily see how a space-filling curve can be generated from a small set. But what isn't really obvious is that this image is made by randomly placing square images into a grid.

Each grid element can have one of two images in it. With this image, I have taken care to create an image that (almost) doesn't have any obvious loops in it.

Well, OK, it does have one, in the lower left corner. But it doesn't have any circles in it. That, it turns out would be legal in this particular pattern grammar. Loops (and loops within loops within loops) would also be legal.
Here is the basis set for this particular image. It consists of two tiles as you can see. In each square, one tile connects the middle of the top edge with the middle of the right edge and also connects the middle of the left edge with the middle of the bottom edge. The other tile is either a mirror-symmetry of the first, or it is rotated 90 degrees from the first, whichever you like.

But wait, there are more options along these lines. For instance, I can create two more tiles that connect vertically and horizontally. In one tile, the horizontal crossing takes precedence, and in the other, the vertical crossing takes precedence. Now what would happen if we randomly expressed a tile from this basis?

Well, we can easily generate this test as well. Here, to the left, we see that suddenly, this image is starting to look like a subway map.

This grammar can generate interweavings of any kind. Weavings are made of warp (vertical threads) and weft (horizontal threads). Since one element is warp-over and another element is weft-over, we can represent all possible interweavings.

But what makes this interesting is that the threads can also turn.

You can represent knots as well, of course, since we include pass-under and pass-over elements.

Suddenly, this pattern has taken on more dimensions than before. Just 4 elements and so much richness of representation!

I thought on this, and realized that I could also include ends: threads that do not cross the tile, but rather end. I increased the basis by 4 more tiles. This time, the four diagonal sad-faces were added.

It is not obvious to me what this grammar will generate. But I think it's going to be interesting nonetheless! This seems to leading to noodles and other patterns made of threads that have ends. What will it look like?

Here is an example output randomly from this grammar. The most interesting part is that the complexity has definitely increased. Notice that the threads seem to look like bacteria in a culture mold. But regular, of course.

One obvious thing is that dots have appeared. And letters, like lower-case f and t.

You can identify each thread by itself, and where it goes.

And yes, a sad face has appeared in upper right.

After making this, it occurred to me that it would be possible to add 3 more elements to the basis. A tile containing 4 ends, and horizontal and vertical crossings with ends on the other sides of the tile.

Here is the new basis set, with the three new tiles added.

Perhaps the new elements look like the division symbol. But with the interconnections, this will likely be obscured by the neighboring elements, hiding it.

One thing we can say just by looking at the basis set: there might be more dots than in the last generated example. And more vertical and horizontal lines, particularly those which have no other line crossing them. So this will undoubtedly lead to more open space in some areas.

Here is the result of generating a random placement using this new basis set.

The result is using fewer and fewer curves. There are twice as many free-floating dots as in the last one.

One thing to remember is that each previous level is really just a subset of this next level.

Perhaps even more interesting than ends is the possibility of branching. We can assume that there are no curves and try to construct a maze grammar.

This would not have crossings, per se, rather it would be more square, with cross, the four t's, horizontal and vertical paths, with ends as well, but not really circular or curved. It occurs to me to try this case.

Here is the new basis, that operates only horizontally and vertically, and contains branching. I don't think it could generate a maze, though. On the average, it will probably generate circuits (closed loops).

This grammar is very foursquare. I have rounded off the edges to make it a little more presentable.

Here is the result of generating a random placement from this basis set.

It is a very busy pattern with very few dots. It does tend to be a little maze-like, and the pieces in it are heavily connected.

The tiling grammars I have presented here are reminiscent of Wang tilings.

Perhaps they are even closer to Thue-Morse tilings.

All of these are related to the work I did back in 1993, when the image hose was just invented and I realized that it might bear on this class of tiling grammars.