Bonus Friday Post “Fractal Valentines Day!”

Many of you have probably seen this old XKCD comic:

sierpinski_valentine

But it takes a special brand of geek to see that drawing as a challenge. Here’s my first attempt and its axiom:

heartLSysFirstStage

heartLSys_lq

Unfortunately, L-Systems aren’t really designed well for curves. You can draw them, but you’ve got to do something like “move forward small amount, turn 1 degree, repeat 180 times”. In L-System code this looks like this:

“DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DF”

DF = Move D forward, E+ = Turn 1 degree

But this is Valentine’s Day, and Valentine’s day should be a little hard. So here’s attempt 2:

heart2LSysFirstStage

heart2LSys_lq

 

As you can see a little closer to the mark, but we’ve got some overlap and the heart is kind of pointy at the curve transition. For attempt three I did a trick I used to do with cakes. Take a square, and add two-halves of a circle to two sides:

heart3LSysFirstStage

heart3LSys_lq

And then because it’s me, I thought, “can we make the heart just a tidge taller”:

heart4LSysFirstStage

heart4LSys_lq

Now most people would stop there, but I played around with a couple of other variants:

heart5LSysFirstStage

heart5LSys_lq

heart6LSysFirstStage

heart6LSys_lq

And then I thought, well now that I have this heart object, what else can I do with it?

heart4CloverLSys_lq

heart6CloverLSys_lq

heart12CloverLSys_lq

Here’s the code for “Heart 3” my first successful attempt, which works with the programs in Chapter 4 of my book:

<?xml version="1.0">
<lSystemSpec>
 <imageAttr prefix="heart3LSys" lvl="6" scaling="0.5"></imageAttr>
 <ruleMappings turnAngle="15" length="250">
 <rule cmd="forward" char="F"></rule>
 <rule cmd="right" char="+"></rule>
 <rule cmd="left" char="-"></rule>
 <rule cmd="begRecr" char="["></rule>
 <rule cmd="endRecr" char="]"></rule>
 <rule cmd="move" char="fg"></rule>
 </ruleMappings>
 <transformations axiom="Cg[X]BgA-TfRS-[X]S-RTfA-Bg[X]">
 <replace char="X" replStr="Cg[X]BgA-TfRS-[X]S-RTfA-Bg[X]"></replace>
 <replace char="f" replStr="F"></replace>
 <replace char="R" replStr="DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DFE+DF"></replace>
 </transformations>
 <variables>
 <var char="A" value="9"></var>
 <var char="B" value="4.25"></var>
 <var char="C" value="-4.25"></var>
 <var char="D" value="0.034906585039886591538473815369772"></var>
 <var char="E" value="0.066666666666666666666666666666667"></var>
 <var char="S" value="3"></var>
 <var char="T" value="4"></var>
 </variables>
</lSystemSpec>

Technically the “R’s” should be replaced with the whole long string and you can get rid of the R replacement rule, but I left it this way for readability. High-quality versions of the image are available by clicking on the image.

Happy Valentine’s Day, especially to you, the little red-haired girl 😉

2 Comments

Filed under Uncategorized

2 responses to “Bonus Friday Post “Fractal Valentines Day!”

  1. Very cool. The fractalator strike again!

  2. Now this is a pretty geeky way to say Happy Valentine’s Day, and I love it! (My valentine’s gift this year included a T-shirt that says, “I ❤ my geek.")

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s