New Koch Snowflakes

I was working with Thomas a few weeks ago in his quest to learn how to create fractal images.  He essentially asked the following question:  How can you locally change the appearance of a fractal?

For example, consider the well known Koch snowflake (which we discussed earlier on Day007), shown below.

Day033Koch1bThomas asked if it might be possible to keep the overall shape of the snowflake, but change the details at the edges.  To discuss this possibility, let’s recall the algorithm for producing the snowflake (although this algorithm produces only one-third of the snowflake, so that three copies must be put together for the final image):


  • if n = 0, then draw a line segment,  otherwise:
  • sf1(n-1); turn -60; sf1(n-1); turn 120; sf1(n-1); turn -60; sf1(n-1)

This is “pseudocode” for drawing part of the snowflake n levels deep.  The difficulty is that the segments are drawn only when n = 0.  Thomas was wanting something different to happen, say, at level 3 and below in an algorithm which recursed 6 levels deep.

Then it occurred to me — there’s no reason the “otherwise” couldn’t be broken down into further cases:  make the recursive call depend on the value n.

But in order to do this, I needed to use a different recursive call.  What to use?  Well, it happens that by slightly changing the angles in sf1, the snowflake undergoes a rotation by 30 degrees.  Here is the pseudocode, along with the image.


  • if n = 0, then draw a line segment,  otherwise:
  • sf2(n-1); turn 120; sf2(n-1); turn -60; sf2(n-1); turn 120; sf2(n-1)


So how do we combine these fractals?  As suggested earlier, break down the original “otherwise” clause.  The following algorithm adds a “little” of the second snowflake to the first since the second algorithm is only called when n = 1.


  • if n = 0, then draw a line segment, otherwise:
  • if n = 1, sf2(n-1); turn 120; sf2(n-1); turn -60; sf2(n-1); turn 120; sf2(n-1)
  • else sf1(n-1); turn -60; sf1(n-1); turn 120; sf1(n-1); turn -60; sf1(n-1)

Here is the resulting fractal image (recursing 6 levels):


You can already see a difference.  Now let’s try adding a little “more” of the second snowflake by using the second algorithm when n is 1 or 2, as shown below.


  • if n = 0, then draw a line segment, otherwise:
  • if n <= 2, sf2(n-1); turn 120; sf2(n-1); turn -60; sf2(n-1); turn 120; sf2(n-1)
  • else sf1(n-1); turn -60; sf1(n-1); turn 120; sf1(n-1); turn -60; sf1(n-1)


Going one level further — using the second algorithm when n is 1, 2, or 3 — produces the following curve.Day033Koch5

One level further yields:


And we’re done, since the next level will in fact give the rotated snowflake sf2(6) (although pieced together a little differently — but the resulting fractal is the same).

Now I’ll leave it up to you.  There’s really so much to explore here.  Here’s just one example.  Adding just one additional call to sf2(n-1) after the last one in the algorithm produces the following image:Day033Koch7Amazing, isn’t it?  Such a small change results in a very different feel to the final image.  And of course once smaller changes are made, there’s no reason to stop.  Maybe branch into more than two fractal routines?  Or maybe perform sf1 when n is odd, and sf2 when n is even.  Or….

The only limitation, it seems, is one’s imagination.  Comment if you create something interesing!

The Joy of Ink II

Last week, I talked about finding a printer I could work with — in my case, a local print shop recommended by my housemates.  This week, I’d like to talk about some of the details of getting my prints to look just right.  But a word of caution:  your situation will likely be quite different!  But I hope that what I have to share can give you some idea of  the issues you need to think about.

Of course the primary issue is color.  Unless you’re very lucky, the first time you print a digital image will be somewhat disappointing.  Shops will have different printers, and different brands and quality of ink and paper.  It’s almost impossible to predict what an image will look like, even if you’re aware of some of these differences.

I did decide to buy a subscription to Photoshop — many shops use it, and for a few dollars a month, well, I decided that was one variable I could control.  At least we’d be working with the same software….

I made sure my image was in CMYK mode (Image > Mode > CMYK Color in Photoshop), since printing with ink involves subtractive color.  Some trial and error revealed that if I added +80 on the Magenta–Green scale and +40 on the Yellow–Blue scale (Image > Adjustments > Color Balance) and then printed, the colors came pretty close.

I’m learning that pretty close is good enough…it’s almost impossible to match colors exactly.  When I write code I can be as precise as I like — but I have learned to be more flexible when it comes to printing.  There’s no other sane choice….

And sometimes, well, there’s a pleasant surprise.  I was printing out my favorite spiral for an Art Exhibition at a mathematics conference,


and it was pretty far off — but to my real surprise, good.  The colors were a bit muted, giving a more naturalistic, organic feel, and the contrast with the greenish background was more intense.  I liked it, and decided to use it.

I was beginning to realize that not only is it impossible to exactly duplicate the colors on your screen in print, but it might very well be the case that you want the colors of the printed image to be different.  A computer screen is backlit, while a print isn’t — and this impacts the way you see an image on your computer screen vs. the way you see a printed copy.  You interact with the image differently, because the media are different.

So there’s definitly a give-and-take with color.  Resolution is the next big issue.  Your computer screen is essentially a rectangular grid of pixels — possibly a very large number of them (my computer screen has about 1.3 million) — but still, any image is just an array of colored dots on a grid.

This issue was significant in printing out the following image for the same Art Exhibition.


The first attempt was just dark, with very little yellow or white visible.  In fact, I almost thought it good enough — I even purchased it and brought it home with me — but as I kept looking at it, well, I knew it wasn’t right.

I looked at the code which produced the star, and found a possible suspect — the line width.  I had set it to 0.002 inches — very thin.  Because one color of ink bleeds a little into the next color, there was too little of the lines left to be clearly visible.

So I decided to try doubling the line width to 0.004 inches.  It was perfect!  I have to admit, it was the easiest fix I’ve ever made — seems it’s never that easy.  But the real point I want to make is that when I doubled the line width, the image on my computer screen did not change.  There were no visual clues to tell me that my lines were too thin — after all, you can never get a line thinner than a pixel.

When I first starting programming computer graphics, I would frequently set the line width to zero, meaning the printer would print the thinnest line possible.  With the resolution of printers at the time, this was just perfectly adequate.Day028rhdodecaNo longer.  I did some experimenting and found that for producing nets for polyhedra (such as the rhombic dodecahedron above), a line width of 0.006 is good.  Easily visible, but not too thick.  And as mentioned earlier, when working in thousandths of an inch, one or two can make a big difference in what the final image looks like.

I have to admit I haven’t really dealt much with the issue of paper — but there are definitely things to think about here.  Thickness, gloss, etc.  For my immediate needs, a fairly thick, semi-glossy paper was fine — I didn’t need to make a museum-quality print.  But soon I’ll be branching out into making greeting cards, and then, I’ll need to confront the paper issue head on.  Working in small batches on expensive paper means it’s a lot harder to make any money….

So these are the main issues I’ve had to deal with so far as a digital artist.  I’m sure they won’t be the last — and if (when!) I learn anything else that’s really significant, I’ll write a Joy of Ink III.

I’m really hesitant to give advice — but having said that, here goes.  Be patient and flexible.  There are a lot of details to consider, and it’s very difficult to get a project done perfectly and quickly.  There is definitly a learning curve — and I think there will always be a learning curve, since technological progress will continue to increase the number of affordable options for the digital artist.  But rather than be frustrated by this, I think it’s saner to be excited by it.  What we take for granted today was almost unthinkable ten years ago — so who can predict what will be possible ten years from now?  Certainly not me.  But that’s half the fun of it….

The Joy of Ink I

Think twice about becoming a digital artist.

While at my local print shop — again being frustrated at trying to get colors to print correctly — Xander (one of the printers who works there) casually mentioned that digital art as seen on a computer and digital art as seen in a print are two different media.  (By the way, the shop is Autumn Express in the Mission District, San Francisco.  Go there!)

I had never thought about digital art in that way before.  The idea prompted me to write a few blog posts about my experience with light and pigment.  It’s been a bumpy journey — but ultimately rewarding.  I hope that writing about my successes and challenges might make it a little easier for the next aspiring digital artist….

In the beginning, I thought it would be easy.  For my first solo exhibition (when I was teaching in Princeton, NJ), my art teacher’s friend and colleague generously printed my images for me, and frankly, they were perfect.  (Thanks, Bryan!  By the way, Bryan does some amazing work — check out his website here.)

So I thought, “Hey, Bryan got it right the first time.  No problem!”  But, as it turns out, the typical print shop printer is, well, not Bryan.  There’s an art to printing, and some printers are more artisitic than others.

For example, when I was in Florida in Fall 2014, I designed some greeting cards to sell at a gallery for local artists.  I needed to find somewhere close by where I could get them printed relatively inexpensively — I wanted to make a little money out of the adventure.  I took my designs to a local shop, printed them out, and they looked horrible.  Colors washed out and muted — bland.  There was no one who worked there who knew much about color, so I was stuck.  I gave up on this project.

I had better luck with Ron (of No Naked Walls in Port Richey, FL).  He had a real interest in printing and photography — even had a collection of some very old cameras.  And he had just bought a brand spanking new printer (not sure how many thousands of dollars it cost), and enjoyed playing around with it.

Gamut is the issue.  A color gamut is the range of colors you can produce with your device.  A computer screen uses red, green, and blue phosphors which are excited by electron beams to generate colors (see a simple explanation here).  Using light to create color sensations is referred to as additive color.  A printer, on the other hand, mixes pigments — usually cyan, magenta, yellow, and black — to create color, which is known as subtractive color.

Now this isn’t meant to be an in-depth tutorial on color (that would take far too many posts) — but the bottom line is that the gamut of colors produced by your color monitor is not the same as the gamut of colors produced by your local printer.  (And if you want to know more, just google any of the terms in this brief discussion and you’ll find lots more to read.)

And it gets more problematic when you realize that different monitors may  also have different color gamuts.  Monitors may be calibrated in many ways, each rendering coloring differently.  So what looks just right on one laptop may look slightly off on a different one.

But Ron was willing to work with me.  He’d take my jpeg, upload it into his version of Photoshop (again, differences!), and then print it out — and it wouldn’t look like it did on my computer screen.  We’d work back and forth — testing small sections of a large print, changing the colors slightly, then printing again — until we got something that looked good to me.

What you’ll find out is that not every printer knows all that much about color, and not every printer is willing to work with you.  The first printer I went to in San Francisco, Photoworks on Market St., really wasn’t all that helpful.

I was hopeful about an online printer — ProDPI — I heard about from a colleague at a conference.  He had good luck with having prints made and shipped directly to clients.  I wasn’t so lucky.  When I had samples printed and they were too yellow, I was (after many email exchanges) politely informed that because they dealt mainly with portraits, their printers were calibrated to print colors a little warmer, and no, they did not intend to modify their profile any time soon.

I did try adjusting the colors and printing a second set of samples, and they were also not quite right.  I suppose I could have continued this back-and-forth with waiting for samples to arrive in the mail, tweaking them, and repeating the cycle — but I didn’t want to do this with every image I wanted to print.  So I gave up on ProDPI.

How I found Autumn Express was completely serendipitous.  I needed to get some prints made for an exhibition at a big national mathematics conference, and I wasn’t having any luck.  I was visiting friends over our winter break, and I even frantically called to see if we could visit some local print shops while I was traveling.

But some of my housemates have a video game company, and they get stuff printed all the time.  I happened to ask JJ where they got their material printed, and the rest is, well, history.

I never knew finding a good printer would be so difficult.  I needed to understand color gamuts.  But more importantly, I learned that printing is not just a matter of pushing a few buttons, but is really an art.  Bryan made it look so easy.  But it’s not.

Next week, I’ll talk about a few specifics — settings in Photoshop, for example.  And I’ll say a little more about how what you see on your computer screen might be rather deceiving.  But then you’re on your own….

Creating Fractals IV: Results!

It has been a while since I wrote about making fractal images — and you might recall that  I made several observations about how the images were drawn, but didn’t actually prove that these observations were valid in any general sense.

That has changed!  A few weeks ago, I decided that it was time to bite the bullet.  I had a concise way to describe what angles were chosen (see Creating Fractals, Day008, and Creating Fractals II:  Recursion vs. Iteration, Day009), I accumulated a lot of empirical evidence that validated this description, and now it was time to prove it.  I made a goal of solving the problem by the end of this semester.

It is amazing what a little determination can do!  I went back to the code I wrote last October, stared at and studied countless sequences of angles and their corresponding images, and within a few days had a working hypothesis.  Less than a week had gone by before I had a fairly complete proof.  What I thought would take me an entire semester took me about a week.

In today’s post, I’ll talk about specific cases which directly relate to my previous blog posts.  I won’t really prove anything here, but instead present the idea of the proof.  When I write up the complete proof, I’ll post a link to the paper.

The main insight came from looking at sums of angles (mod 360).  Let’s look at a specific example, using angles of 40 degrees and 60 degrees (both counterclockwise).  These angles produce the following image:


The angle sequence follows the pattern described in Creating Fractals II:  40, 60, 40, 40, 40, 60, etc., where the “40” occurs in position k if the highest power of 2 which divides k is even, and “60” occurs if this power is odd.

The arms in this figure have eight segments each; one such arm is highlighted below.


Now let’s write the angle sums, starting with 0 since the first segment starts at the center and moved directly to the right.  We get


The numbers at the top and left are for row/column reference only.  We begin with 0, and 40, then add 60 to get 100, then add 40 more to get 140, etc.  Once we hit 320 and need to add 60, we write 20 instead of 380 (since as far as angles go, 20 and 380 are equivalent).  This is essentially saying that we are adding angles mod 360 (that is, using modular arithmetic).

These angle sums are the actual directions the lines are being drawn in the plane.  You should be able to see the first two rows of this table clearly in the previous image — as you go around the first arm, your direction changes and points in the direction indicated by the appropriate sum in the table.

But notice the following interesting fact:  each sum in Row 2 is exactly 180 degrees more than the corresponding sum in Row 1!  What this means is as follows:  once the first four segments are drawn, the next four are drawn pointing in the opposite directions.  In other words, they geometrically “cancel out.”  This means that after the first two rows, you’ll return to the origin (as seen above).

You can continue to follow along in the table and view the next arm being drawn, as shown below.


This might seem “obvious” by looking at the table — but it is only obvious after you know how to draw the table.  Then it’s easy!  Even the mathematics is not all that difficult.   I can’t emphasize enough, though, how using the computer to look at several (and more!) examples was a tremendous help in making progress towards how to arrange the table.

Now look at the “20” underlined at the beginning of Row 5.  Because of the recursive pattern of the angles, this means that the next eight segments drawn will exactly repeat the second arm.

Just when do the arms repeat?  The underlined angles (which indicate the direction the next eight segments are starting off) are the beginning of the sequence

0, 20, 20, 40, 60, 80, 80, 100, 100, 120, ….

If we look at the successive differences, we obtain the sequence

20, 0, 20, 20, 20, 0, 20, 0, 20, ….

But notice that this is the same pattern as the sequence of angles:

40, 60, 40, 40, 40, 60, 40, 60, 40, …

This means that the same pattern which indicates which angle to choose also determines which arms are redrawn.  Really amazing!

The separation of 20 degrees between arms is just 60 – 40.  In general, if d is the difference between the two angles, you need to take the greatest common divisor of d and 360, which is often abbreviated gcd(d, 360).  But in this case, since 20 is already a factor of 360, you get the difference back.

Once you know the arms are separated by 20 degrees, you know that there are 360/20 = 18 arms in the final image.

As I mentioned, it is possible to prove all this — and more.  Although we looked at a specific case, it is possible to make generalizations.  For example, there were 8 segments in each arm — and 8 is a power of 2 (namely 3).  But other powers of two are possible for the number segments in arms — 4, 32, 64, etc.

In addition, there is nothing special about degrees.  Why divide a circle into 360 equal parts?  You can divide the circle into a different number of parts, and still obtain analogous results.

The number of interesting images you can create, then, is truly astonishing.  But the question still remains:  have we found them all?  In addition to all the images obtained by looking at arms whose segments number a power of two, it is possible to obtain more regular figures.


Such images are obtained when both angles are the same.  But other than this, I haven’t found any other types of figures.

So are there any others?  Maybe.  Maybe not.  That’s part of the fun of doing mathematics — you just never know until you try.  But I think this question will be a bit harder to answer.  Is some enthusiastic reader tempted to find out?  Perhaps all it takes is a little determination….

Envelopes III: Art and Randomness

This week, I’ll discuss some of the artistic decisions made in producing the images in last week’s post, as well as explore randomly-generated envelopes.

First, let’s look at the following piece.


Initially, I created the image below, which is essentially a recreation of a hand-drawn sketch made in 1983.


Although the lines are clean and precise, the overall impression lacks a hand-drawn feel. I thought to create more texture by having the alternating envelopes go around the origin more than once, as seen here.


I liked this better, but I thought to adjust the angular sizes of the envelopes so that the tips were evenly spaced around a circle. I also adjusted the number of lines in each envelope, producing the final result.

The point of this discussion is to illustrate the process of creating digital art – it’s not as simple as just writing a few lines of code and executing them. There is an iterative give-and-take to the process, which is half the fun of it, anyway.

The next image I’d like to look at is the spiral, shown below.


This is a recreation of an image originally drawn in red, and I thought to create texture by introducing a color gradient. However, using a linear color gradient from the first line to the last produced the following result.


This looked a little off to me – moving toward the green a bit too fast. Now if you remember the discussion of color gradients when we looked at the Evaporation piece (see Day012), you’ll recall that we could create nonlinear gradients which created different visual effects. I found that changing the gradient from linear (a power of 1) to a power of 0.8 produced something I liked more. Of course the difference is not drastic, but I want to illustrate the fact fine-tuning parameters can introduce subtle effects in the final image.

Now on to a discussion of randomly-generated envelopes. Today will only be an introduction – there’s lots more to explore, including envelopes in three dimensions.  But I’ve only begun working on this idea a few weeks ago, and so hope to illustrate how previous work with randomness may be incorporated into the design of envelopes.

Of course just what is random is a more subtle question here. Below is an image where the successive endpoints used to create the envelope are randomly chosen from a unit square, and a color gradient is produced from the beginning to the end to give a sense of motion.


You’ll immediately notice that some envelopes span the entire width or height of the image. As it happens, this makes finding nicely-balanced images difficult. I looked at a few hundred images before I found the one above – most lacked balance.

I also wanted to try bright colors against black – this produces nice results for an online blog (though not so wonderful for a printed image). Again, I didn’t like the results obtained by allowing the points determining the envelopes to be completely random. So I introduced a constraint that the endpoint of the next segment had to be “close” to the previous one – in the image below, the endpoints could be no further than one unit in either the x- or y-direction from the previous point. So there are more local effects, and none of the broader lines slicing the image in half.


The image looked a little too square, and I thought the contrast too much for so many envelopes.  So I looked at a few hundred more images on a wider field, this time in yellow. I found one with some interesting interactions, shown below.


Now I felt I was getting somewhere. But I thought the image looked a bit too flat – I wanted to add some texture or dimensionality to the image.

The first thing I tried was slightly varying the yellows used to draw the lines. This helped to add a measure of interest to the envelope. But the background needed some work.

I wanted the background to contrast the flowing curves of the envelopes, and so I thought some overlapping squares of varying dark shades of gray might do the trick. Here is the result.


The background took a few hundred iterations as well. Now I didn’t want the squares too small, and I didn’t want too many – the sizes of the squares should compare to the sizes of the individual envelopes, and there should be roughly as many. But the problem was that randomly-generated sets of squares would often leave too many gaps in the background – and simply overlaying a background of a single shade of gray wasn’t particularly pleasing.

So I had to play with the parameters generating the overlapping squares, as well as try a few hundred iterations until I found something with a nice balance. In addition, I wanted the background to be “interesting” in the largish hole just left of center – some iterations just produced a solid gray there, which didn’t work for me.

It took a bit of time – as well as feedback from my friend Sandy (thanks, Sandy!) to whom I showed successive drafts of this image – but I finally found a combination of colors/backgrounds which I felt held together. Of course you might think otherwise – and you are welcome to give it a try and create your own image with randomly-generated envelopes….

I hope this helps to illustrate the creative process – one of the main themes of this blog. While a final image may look complex with various different aspects interacting with each other, it’s not always the case that each aspect was conceived of at the same time. This is the great thing about computer-generated art – it’s so easy to explore a multitude of ideas without leaving the comfort of your keyboard.

But this is also perhaps the greatest challenge – because you can do so much, finding the right balance between simplicity and complexity in part distinguishes computer-generated images from computer-generated art.

Finally, I cannot resist including an image I tweeted a few days ago @cre8math — a variation on the spiral theme.  I find it unusually compelling.


Envelopes II: Making Spirals

While I don’t intend to make a habit of midweek posts (though thanks for the idea, Dane!), last week’s entry was so popular that I thought I’d write a short post on how the spiral designs are created.  Here’s one of last week’s images to refresh your memory.


These are not difficult to create,  but because of all the overlap of lines, it’s not immediately obvious how they are generated.  The image below shows the first forty line segments drawn, and highlights the endpoints of these segments.


The first line drawn is horizontal, and the endpoints are 180 degrees apart.   More lines are generated by having the orange endpoint (starting at the right) move 4 degrees counterclockwise, while the green endpoints (starting at the left) move just 3 degrees.  As a result, the endpoints of the second segment are just 179 degrees apart on the circle.  The orange endpoints start gaining on the green endpoints, closing the gap by 1 degree with each successive segment.

So the final spiral includes exactly 180 segments, which may be expressed in a form which may be easily generalized (and which is used in the Python code).  Note that the “180” on the left side of the equation represents the number of segments drawn, and the “180” on the right indicates the angular distance that the endpoints of the initial segment are separated on the circle.

180 = \dfrac{180}{4-3}.

All 180 segments are shown below, where the endpoints are retained to illustrate the process (although note that many endpoints are written over as the algorithm progresses).


The Python code is fairly short (here is the Sage link — look at some of the earlier posts about using Sage if you haven’t used it before). The only mathematics you need to understand is the standard conversion from polar to rectangular coordinates — it’s much easier to describe the endpoints first in polar coordinates since the radius of the circle is fixed and only the angles the endpoints make with the center of the circle change.

Finally, I include an image created with contrasting colors on the background as well.  Create your own version, and post as a comment!


Envelopes I

Most of us have probably created a mathematical envelope, although we likely didn’t call it that.  Below is an example which may easily be sketched on a piece of graph paper.  You can see the “move one up/down, move one left/right” method of determining the ends of the line segments.  I created this envelope of lines using Python — we’ll look at the code later so you can make some of your own.

I first began sketching envelopes when I was an undergraduate.  Of course they were aesthetically quite interesting — but as a mathematician, you cannot help but ask exactly what curve you’re approximating by drawing an envelope of lines.

Although it seems that you might be drawing tangents to a circular arc, this is not the case.  By continuing the pattern of moving one up/down and left/right, the envelope in the first quadrant develops into the following figure.


You can fairly easily see a parabola forming — and this parabola is in fact the curve whose tangents we drew on our graph paper.

How can we prove this?  We need a theorem about tangents to parabolas, which we state as it applies to the case at hand, as shown below.Day020Envelope3

Here is how the theorem goes.  Suppose P and Q are points on a parabola whose tangents intersect at R.  If X is a point on the parabola between P and Q, and if the tangent at X intersects PR at M and QR at N, then

[PM] / [MR] = [MX] / [XN] = [RN] / [NQ],

where we use “[AB]” to mean the length of the segment AB.  But in our case, [PR] = [QR], so this means that

[PM] = [RN]  and  [MR] = [NQ],

which validates our “one down, one right” method of creating endpoints of tangent segments.  This is because by moving down one and right one, we are preserving the relationship [PM] = [RN], and hence also [MR] = [NQ].

For the curious reader, this helpful theorem about tangents to parabolas is very nicely proved by Steven Taschuk in his Notes on tangents to parabolas on p. 5 (where the names of points in my diagram above correspond to the names of points in his proof of the theorem).

So they’re parabolas!  Not what you’d expect at first glance.

Of course back when I was beginning college, there was no easy way to create desktop graphics, and so I used the tried and true pen-and-paper method.  I took a photo of one of my favorites from that time period.


Drawing these figure takes patience and concentration.  I distinctly recall the first draft of this piece.  If you look at the left square, you’ll notice that the blue lines look like they’re underneath the red lines.  This isn’t hard to do — just draw the red lines first, and then when drawing the blue lines, just stop at the red and continue after.  But I lost focus for just a second, and drew a blue line right over the red lines — and then had to start over.  There was no erasing.

For those of you who want to try creating images by hand, a word about technique.  When using an ink pen, the ink tends to blot — and if you drag the pen along a ruler, you might get end up with a smear of ink.  So keep a napkin or paper towel handy, and wipe the tip of your pen on the paper towel after drawing each line.  It’ll save you a lot of grief.

Despite the relatively simple method of drawing envelopes of lines, there is ample room for creativity.  Here is a computer-generated version of a drawing dated December 24, 1986.  It’s another of my favorites, and I love the effect of bright color against black.


There’s no reason to stop at purely geometrical designs, either.  Here is an abstract half-face of a tiger, created with a simulated graph paper background.


And then there’s polar graph paper!  When you wanted a graph, well, you just drew it — there was no graphing calculator/computer to do it for you.  So you had graph paper handy.  Below is a design I created just for this post, based on some older sketches.


Here’s another image based on a sketch made on polar graph paper.


It’s been really interesting to experiment with the computer, since designs which might have taken hours to draw can be rendered in a few seconds (after you’ve done the programming, of course).

Envelopes are not restricted to being created by lines, however.  The figure below creates a cardioid from tangent circles.


A base circle (in red) is given, and a point on the circle is selected (the white point at the left).  Now for every other point on the circle (like the red point), create a circle by using that point and the white point as ends of a diameter of the circle (drawn in black).  These circles are internally tangent to a cardioid.

I don’t have room for the proof of this construction here, but there is a very nice book called Envelopes by Boltyanskii (just google it) which illustrates many additional examples of envelopes as well as techniques to determine what the resulting curve is.  Some of the techniques do involve calculus, so be forewarned!  This book was my real introduction to a study of mathematical envelopes.

Now it’s time for you to create your own envelopes!  You can click on the Sage link to follow along and alter the code as you see fit.

The routines aren’t really too complex.  Note the use of vectors in Python to make working with the mathematics fairly simple.  This is so we can compute the endpoints of the segments of the envelope easily.  The mathematics involved is illustrated in the following figure.


It looks more complicated than it is.  Since P_i is between P and R, we may write P_i as a weighted average of P and R.  We must do so in such a way that i=0 gives the point P=P_0, and P_{n-1} is just above R.

Similarly, Q_i is a weighted average of R and Q, and must be such that Q_0 is just to the right of R, and Q_{n-1}=Q.  Take a moment to study the figure and see that it all works out.  Note that the variables in the code mimic those in the figure exactly, so at least there is visual proof that the labels are correct!

So I’ll leave you to go ahead and experiment.  Feel free to comment with images you create using the Python code.  And stay tuned for next week, when I’ll talk about creating random envelopes.  There’s some really interesting stuff going on there….

Geometrical Dissections II: Four to One

This week, I’d like to discuss a piece of artwork which began as a geometrical dissection — I call it Four to One.


I thought it would be interesting to discuss the process of creating such a piece from beginning to end.  The creative process is not really mystical, but because we so often only see the finished product, it may seem that way at times.

It all began about 15 years ago, when I was teaching the Honors Geometry course I mentioned in last week’s post.  In Greg’s book Dissections Plane & Fancy, he takes a few chapters to discuss dissections from squares to other squares — frequently two different squares to one, or three to one.  But there was very little about four-to-one dissections, so I thought I’d explore this avenue a bit more.

I can’t recall precisely how I arrived at the identity


I might have written some for loops — but computers were not as fast back then….  Likely I used something like Lebesgue’s formula on p. 80 of Greg’s book, which gives a formula for creating three-to-one square dissections.  Then if one of those squares could be written as a sum of two others, I’d have a four-to-one dissection.  In particular, once I (might have!) found out that


I could use the fact that 15^2+36^2=39^2 (which is just a multiple of the Pythagorean triple (5, 12, 13)) to obtain the possibility of a four-to-one dissection described above.

Now this only suggested the puzzle, not the actual dissection itself.  And there certainly is a dissection — at the very least, we can cut up all the squares into 1\times1 unit squares and reassemble!

This is hardly an elegant solution; but I did come up with the following one:


I liked it because each square was cut into just two or three pieces, which was particularly nice.  Moreover, only one piece needed to be rotated.  But even though the number of pieces is relatively small, there is still the possibility that a dissection may exist using fewer pieces.

Of course my original solution was sketched on a yellowing piece of graph paper — but what to do with it now?

My first attempt looked like this:


I was thinking of creating various pathways through the dissected squares so that when they were rearranged, the pathways would still line up.  I abandoned this approach, however.  I can’t remember exactly why, but the results didn’t appeal to me — and besides, the paths themselves actually had nothing to do with the dissection puzzle itself.

But then I had the thought — which was in fact a real challenge — can I communicate what’s happening with the dissection using only one square?  In other words, could I depict the geometrical dissection by just showing the largest square without giving the viewer the four smaller squares?  I think what might have moved me in this direction is that there was just no elegant way of putting all five squares together in a composition.  There were just too many corners.

So I though of overlapping the smaller squares onto the largest square, as shown below (note:  you’ll notice an error in the geometry, but as it was a draft I discarded, I didn’t bother to fix it):



Now if you look very carefully, you can find all the pieces of the dissected squares in the largest square.  There is some overlap, of course — but smaller circles were overlaid on larger ones so colors from both circles could be seen.  (I copied the original dissection again so it’s easier to compare.  I used different colors as the images were created at different times, so watch out! )

I liked the idea — I felt I was getting somewhere.  But I wasn’t happy with the colors.  Now creating mathematical art makes you hungry — I can clearly recall driving to lunch while I was in the middle of this project, and I can even remember the road.  It was Fall in Princeton, NJ, and the leaves had already turned color.  No more oranges and reds — but lots of greens and yellows, as well as browns from the tree trunks.  My color palette!

What intrigued me about the idea was the fact that I was working with a very abstract, almost purely mathematical problem — and here I was, thinking about using organic colors from nature, from my life experience.

Now I had already been working with the ideas from Evaporation, and realized if I was using an organic palette, I couldn’t have the circles be regular, precise — and the colors couldn’t be pure either, just like you might find hundreds of shades of yellow in a Fall forest.


So, as shown in this close-up of Four to One, the colors were varied by using random numbers just as was done for Evaporation, but there were no extremes — each piece of each square had to be clearly recognizable if the dissection was to be clearly seen.

The sizes of the circles varied as well, helping to contribute to a natural texture.  Here, you can clearly see how smaller circles were overlaid on larger circles for the two-color effect.  The smaller circles, however, had only about one-fourth the area of the larger ones, so it was clear which color was dominant.

And there it is!  The creative process is not magical, not mystical — in fact, much of the time it seems to consist of failed inspiration….  Consider yourself lucky if your first attempt turns out to be your last as well — but more often than not, creativity is an iterative process involving constant revision.

So my advice is to stick to it!  Don’t worry if the first attempt isn’t what you imagine.  Now I used Mathematica to create this image — and I’ve been programming in Mathematica for over twenty years.  So I’m pretty good at taking an idea and implementing it fairly quickly.  But if you’re relatively new to programming, you’ve got to be patient with your programming skills as well.  I can tell you though — it’s worth it.  Don’t let anyone else tell you any different….

Evaporation II

Last week, we began exploring the piece Evaporation.  In particular, we looked at two aspects of the piece — randomness of both the colors and the sizes of the circles — and experimented with these features in Python.  Look at last week’s post for details!


Today, we’ll examine the third significant aspect of the piece — the color gradient.  The piece is a pure sky blue at the top, but becomes more random toward the bottom.  How do we accomplish this?

Essentially, we need to find a way to introduce “0” randomness to each color at the top, and more randomness as we move toward the bottom.  To understand the concept, though, we’ll be introducing 0 randomness at the bottom, and more as we move up.  You’ll see why in a moment.

Let’s first look at a linear gradient.  Imagine that we’re working with a 1\times1 square — we can always scale later.  Here’s what it looks like:


The “linear” part means we’re looking at randomness as a function of y^1=y.  So when y=0, we subtract y=0 randomness to each color.  But when y=1/2, we subtract a random number between 0 and y=1/2 from each of the RGB values.  Finally, at the very top, we’re subtracting a random number between 0 and 1 from each RGB value.  Recall that if an RGB value would ever fall below 0 as a result of subtraction, we’d simply treat the value as 0.

Why do we subtract as we go up?  Recall that black has RGB values (0,0,0), so subtracting the randomly generated number pushes the sky blue toward black.  If we added instead, this would push the sky blue toward white.  In fact, you can push the sky blue toward any color you want, but that’s a little too involved for today’s post.

The piece Evaporation was actually produced with a quadratic gradient.  Let’s look at a picture first:


That the gradient is quadratic means that the randomness introduced is proportional to y^2 for each value of y.  In other words, at a level of y=1/2 on our square, we subtract a random number between 0 and


You can visually see this as follows.  Look at the gradient of color change from 0 to 1/2 for the quadratic gradient.  This is approximately the same color change you see in the linear gradient between 0 and 1/4.  Why does this happen?  Because when you square numbers less than 1, they get smaller.  So smaller numbers will introduce less randomness in a quadratic gradient than they will in a linear gradient.

We can go the other way, we well.  If we use a quadratic gradient (exponent of 2>1), the color changes more gradually at the bottom.  But if we use an exponent less than 1 (such as in taking a root, like a square root or cube root), we get the opposite effect:  color changes more rapidly at the bottom.  This is because taking a root of a number less than 1 increases the number.  It’s easiest to see this with an example:


In this case, the exponent used is 0.4, so that for a particular y value, a random number between 0 and y^{0.4} is subtracted from each RGB value.  Note how quickly the color changes from the sky blue at the bottom toward very dark colors at the top.

Of course this is just one way to vary colors.  But I find it a very interesting application of power and root functions usually learned in precalculus — using computer graphics, we can directly translate an algebraic, functional relationship geometrically into a visual gradient of color.  Another example of why it is a good idea to enlarge your mathematical toolbox — you just never know when something will come in handy!  If I didn’t really understand how power and root functions worked, I wouldn’t have been able to create this visual effect so easily.

Now it’s your turn!  You can visit the Evaporation worksheet to try creating images on your own.  If you’ve been trying out the Python worksheets all along, the code should start to look familiar.  But a few comments are in order.

First, we just looked at a 1\times 1 square.  It’s actually easier to think in terms of integer variables “width” and “height” (after all, there is no reason our image needs to be square).  In this case, we use “j” as the height parameter, since it is more usual to use variables like “i” and “j” for integers.  So “j/height” would correspond to y.  This would produce a color gradient of light to dark form bottom to top.

To make the gradient go from top to bottom, we use “(height-j)/height” instead (see the Python code).  This makes values near the top of the image correspond to 0, and values near the bottom of the image correspond to 1.  I’ll leave it to you to explore all the other details of the Python code.

Please feel free to comment with images you create using the Sage worksheet!

As mentioned in the previous post as well, each parameter you change — each number which appears anywhere in your code — affects the final image.  Some choices seem to give more appealing results than others.  This is where are meets technology.

As a final word — the work on creating fractals is still ongoing.  I’ve learned to make movies now using Processing:

You’ll notice how three copies of one fractal image morph into one of another.  You can find more examples on Twitter: @cre8math.  Once I feel I’ve had enough experience using Processing, I’ll post about how you can use it yourself.  The great thing about Processing is that you can use Python, so all your hard work learning Python will yield even further dividends!

Evaporation I

This and the next post will walk you through how to create digital art similar to Evaporation.  I’ll also show you some Python code you can use yourself to experiment.


There are three significant features of Evaporation. First is the randomness of the colors. Second — if you look closely — the sizes of the circles are also different; these are randomly generated as well. The third feature is the gradient of the color — from a pure sky blue at the top, to a fairly randomly colored row of circles at the bottom. We’ll look at the first two features today.


Let’s look at color. In the figure above, the small teal square at the left has RGB values of 0, 0.5, and 0.7, respectively. The larger square at the left consists of 100 smaller squares. The color of each of these squares is generated by adding a random number between 0 and 0.1 to each of the RGB values 0, 0.5, and 0.7 — with a different random number added to each value. In the middle square, a random number between 0 and 0.2 is added, so this creates a wider range of color values. For the right square, the random numbers added are between 0 and 0.3.

But there is no reason that the ranges need to the same for each color. In the images below, the red values have a wider range of randomness then the green, which is “more random” than the blue.


You can see that different ranges of random numbers create different color “textures.” This is where I think computer meets art — as a programmer, when it comes to creating random numbers, you have to specify a range for the randomness of each variable. The choices you make determine how your image looks. How do you make “artistic” choices? There is no easy answer, of course.

Another way to use randomness is by varying the size of the graphic objects. In the left square below, texture is created by randomly changing the radii of the circles.


In the middle square, the circles are all the same size, but random shades of gray. The right square varies both the size of the circles and their color. The final result depends on “how much” randomness is used. You can try it for yourself by altering the Python code linked to below — change the randomness and see what happens!

I think of my laptop as an art laboratory. It is a place to experiment with different ideas — change this parameter, increase randomness, try out different color combinations. Can you imagine creating any of the images in this post by hand? The computer allows us to perform experiments unthinkable to Rembrandt and Van Gogh. We may lose the texture of brush strokes or the dimensionality of paint on canvas, but what we gain by having a programming language at our disposal makes up for this loss.  At least in my opinion….

Now let’s look at how we can use Python to create these images.  You can experiment with this color and texture worksheet.

There is not much more to say here since a lot is explained in the worksheet. But as you are creating, keep a few things in mind.

1. Use descriptive variable names. This helps a lot when you’re looking a lines of code. Using variables a, b, c, etc., doesn’t help much when you’re looking at a program you wrote a few months ago.

2. Comment liberally! Notes to yourself are easy to use in Python — just start a line (or part of a line) with the “\#” character. You’ll thank yourself later.

3.  Save versions often! I won’t bore you with stories of using Mathematica to do some intense computations for creating digital art — and then read the “Mathematica quit unexpectedly” message on my screen — before I saved my work. I’ve encountered this in Python, too — if you use the online version, you’re connecting to an external server, which hopefully will not encounter problems while you’re working….

Also, as you change parameters, you may want to keep track of results you like. If there are a lot of these, sometimes I write the parameters as comments — so I can reproduce them later. Very important: don’t forget to keep track of the random number seed you use! The feel and texture of an image can vary dramatically with the random number seed, so don’t ignore this vital parameter.

One final thought.  In creating this type of art, I keep in mind the tension between structure and randomness.  You can use the computer to create randomness — but if there’s too much randomness, the image doesn’t seem to hang together.  But if there’s too much structure, the image can lose its interesting texture, and appear flat and purely two-dimensional.  So the choice of parameters in creating randomness is fairly crucial in determining how the final image will look.  And as I’ve said before — this is where technology meets art.  It is fairly easy to create a computer-generated image — but not as easy to create computer-generated art.  The difference is not exactly easy to describe — and certainly opinions will differ.  It is the questions which arise in describing the difference which are intriguing and exciting.

Enough philosophizing. Time to begin the artistic process!  Feel free to comment by posting any images you create using the Python code.