Tag Archives: Programming

Fractal Friday (Julia: c = -0.708108+0.266986i)

Today’s fractal is a Julia set image, a fractal generated on the complex plane like the Mandelbrot set, but one determined by an imaginary constant c. Today’s constant was selected at random from the 40,000 Julia set constants my Mandelbrot scanner has come up with so far. All images were generated using programs from Chapter 6 of Fractals: A Programmer’s Approach (most last night during MasterChef)!

Julia_(-0.708108)_(0.266986)

During the selection of the gallery images I’d typically create about twenty images for each Julia constant, 23 for this post to get 7 final images.

Julia_(-0.708108)_(0.266986)_2

There are 250 gallery images in the bundle (probably about 60 of which were created using this process, so think more than 1000 images, not including those featured in the main text).

BOF_Map26_(-0.708108)_(0.266986)_3_2

You want to select coordinates that highlight the interesting features of the shape. Julia sets tend to be most interesting in the center, though this one also has a couple of good spirals. I also like to dive as deep as I can in a single section to show the fractal’s self similarity (the bundle videos really illustrate this method). You also want to choose colors that frame the features you think are the most pleasing.

BOF_Map26_(-0.708108)_(0.266986)bw2

But some of my favorite pictures are in black and white, though they can often be the hardest to tune precisely.

BOF_Map26_(-0.708108)_(0.266986)_4_bsm2

Here’s one of the spirals using the Boundary Scanning Method (Julia 4).

BOF_Map26_(-0.708108)_(0.266986)_5_bsm

Some of these would make pretty decent watermarks eh?

BOF_Map26_(-0.708108)_(0.266986)_5_3

Have a great weekend!

PS. If you like what you see and want to learn more, be sure to check out the fractal bundle at bentrubewriter.bundledragon.com 🙂

Leave a comment

Filed under Uncategorized

Fractal Friday (Or Sierpinski Saturday)

The Sierpinski triangle (or gasket as his friends call him) is everywhere. It’s hiding in the rows of Pascal’s triangle, emerging from the Chaos Game, or being drawn by turtles in all sorts of imaginative ways. I hear from a reliable source that my EPP teacher from 6th grade might be introducing his class to this ubiquitous fractal. So, for today’s Fractal Friday, I thought I’d show you just a few of the places that gasket likes to show up:

The Chaos Game

SierpinskiChaosGame

1. Choose 3 vertices of a triangle.

2. Pick a point inside that triangle.

3. Each time we draw a new point, we roll a die to determine which vertex we’re moving toward.

4. Draw a point halfway between your current point, and the vertex you rolled.

5. Repeat 1000s of times.

(Read here for more details, or Chapter 1 of Fractals: A Programmer’s Approach)

Affine Transformations

SierpinskiAffineColor

Similar to the Chaos Game, but this time using transformation equations. The basic form of an affine transformation is:

x' = ax+by+e
y' = cx+dy+f

With x and y being your current position, and x’ and y’ being your new point. The constants a-f determine where your next point will go.

For the Sierpinski Triangle we use three sets of equations:

1) x' = 0.5*x + 0.0*y + 0.0
   y' = 0.0*x + 0.5*y + 0.0
2) x' = 0.5*x + 0.0*y + 0.5
   y' = 0.0*x + 0.5*y + 0.0
3) x' = 0.5*x + 0.0*y + 0.25
   y' = 0.0*x + 0.5*y + 0.5

(For more details check out Chapter 2 of Fractals: A Programmer’s Approach)

Turtle Graphics

SierpinskiTurtle

Drawn using a series of commands for drawing a line forward or turning to the right or left. The name “turtle graphics” comes from the imaginary turtle representing the current position of the draw cursor. By giving the turtle a series of commands to draw a line forward, or turn, we can create all sorts of images including the one above. The pseudo-code for drawing the Sierpinski Gasket can be found in Abelson and diSessa’s Turtle Geometry (page 88):

TO NESTED.TRIANGLE SIZE
   IF SIZE < 10 THEN RETURN
   REPEAT 3
      NESTED.TRIANGLE SIZE/2
      FORWARD SIZE
      RIGHT 120

(For more details check out Chapter 3 of Fractals: A Programmer’s Approach or Turtle Geometry by Abelson and diSessa)

L-Systems

SierpinskiGasketLSys

L-Systems (named for Aristid Lindenmayer who created them) are a different way of describing the commands we give to our metaphorical turtle. We use a sequence of characters to give the turtle commands; typically F for forward, + for turn right, and – for turn left. Sometimes we use another character like G or f to move forward without drawing a line.

We start with a string (sentence) of characters called the Axiom. For a triangle this is often F++F++F (each turn is 60 degrees). We go through this string a character at a time and replace certain characters according to our replacement rules. After doing this a number of times, we go through the string of characters again, but this time just execute the commands they represent to draw the final shape. There are a number of L-Systems for drawing the Sierpinski triangle. Here are a few of my favorites:

Classic Gasket

Forward = “F”, Right = “+”, Left = “-“, Move = “G”
Axiom = “F--F--F”
Replacement rules = {F --> F--F--F--GG, G --> GG}

Sierpinski Arrowhead

SierpinskiArrowheadLSys

Forward = "A and B", Right = "+", Left = "-"
Axiom = “A”
Rules = {A --> B-A-B, B --> A+B+A}

Sierpinski Maze

SierpinskiMazeLSys

Forward = “F”, Right = “+”, Left = “-“
Beg recursion = “[“, End recursion = “]”, Move = “f”
Axiom = “F”, Variables {A = 3}
Replacement rules = {F -> [fF][+fA-F][f+f+F], f -> ff}

(For more details look here, or check out Chapter 4 of Fractals: A Programmer’s Approach)

Pascal’s Triangle

pascal-overlay-mod2

Image Source (Math Research, Tips and Trickshttp://malsmath.blogspot.com/2006/12/pascals-triangle-and-prime-numbers.html)

Pascal’s triangle, each row created by adding the numbers of the row above it, contains the Sierpinski triangle (and a number of other interesting patterns), depending on how you shade in the numbers. If you shade all odd numbers, there’s that gasket.

So that’s … seven methods for drawing the Sierpinski triangle. Know any others?

1 Comment

Filed under Writing

Bonus Friday Post (“The Return of Fractal Friday”)

Thanks to everyone who’s supported the book and blog thus far. I thought as a little treat I’d show you a few L-Systems (Chapter 4). Enjoy!

spikeTriangleLSysL4 pentigreeLSys3 antiHexTest2 antiHexTest

I’m considering bringing these Fractal Fridays back as a semi-regular feature. Interested?

1 Comment

Filed under Writing

Bonus Friday Post (Fractal Friday #5)

Some more L-System plants 🙂

The one below could have come off the tree in my backyard.

This one was a little unintentional. It’s the same as the one above, but with scaling at each recursive stage.

Have a good weekend!

2 Comments

Filed under Trube On Tech

When to hit publish

I used to read back every word I wrote in my blog posts (several times).

That lasted about a week.

Sometimes you need to write what you feel, do a quick skim to make sure you haven’t committed too many serious grammatical mistakes (except when the purpose of the post is those mistakes), add a sentence here, tighten a word or two there, and hit publish.

But books are different.

Even in this self-publishing wild west world in which we now live, a sloppily edited book comes off as such. We understand, in fact we embrace the idea, that you’re circumventing the gatekeepers in the publishing houses to give people what they actually might want to read. But really you need to string two sentences together or the reviews might kill you.

On the other hand books can languish from over-editing, over-obsessing. If a book is up to a certain standard the back and forth feedback from reviewers, bloggers, and a wider circle might actually help you to write better material. It might be hard for some writers to hear this, but maybe there’s not really a good excuse for keeping things in a drawer anymore. If it’s been rejected by publishers, but is still a story some niche might enjoy then publish.

But a bad story can set a tone two. One reviewer I read recently thought that the writer had some imaginative and original ideas, but that the characterizations were terrible, and the writing poor. They looked forward to reading future more polished works. This is the unusual case. Usually if someone has paid money for something, and it turns out to not be that good, that will cement their impression of it for a long time.

So what do we do? Do we push something out the door, or do we wait and wait til its perfect?

My other line of work is programming. This may shock you, but most programs are not perfect on their release day. They need patches, bug fixes, and feature enhancements (Yes you Linux users may say otherwise, but even your software gets patches and updates). Weirdly enough, the book of today is more like a program than a book. I know several eBook published authors who are rewriting their novels based on feedback and either republishing under the same title, or creating another book. Kindle supports updates to books, and eBooks reading may overtime have more of a patch structure, with user feedback and further ideas allowing an author to enhance their work, to fix it.

To some this is frightening (me kinda included). I love all my stories, don’t get me wrong (please buy Surreality in Jan-Feb ’13 🙂 ), but the thought of revising them after I hit publish can seem a little never-ending. Maybe a set time frame would make sense. It’s definitely something I’d be open to trying.

But this assumes a book is good enough to start, to get people interested in telling even more story. Otherwise the book leaves a bitter taste.

Ultimately the decision about whether a book is ready is up to you, more than ever. Set a deadline, work your butt off, and get it out there. I can’t wait to read it!

1 Comment

Filed under Books + Publishing, Writing

Work(s) in progress update

Sorry for the irregular posting schedule this week. I’m in training which means I don’t have to come in until 9am instead of my usual 7am. Much as I love you guys, I’m taking advantage of the extra sleep 😉

I thought I’d give you guys a quick update on my “secret non-fiction project”. I’m still on target for October 15-31st, an aggressive but manageable goal. Lately this has been taking up more and more of my time, as would be expected, but sometimes it leaves me without a lot else to talk about (so sorry to those of you around me whose ears have fallen off from all the talking 🙂 ). I’m very excited about this project, and think it will be something that technical and non-technical people can enjoy, but I am equally looking forward to the day I can hit “publish” on Kindle Direct Publishing and settle down for the relaxing tasks of marketing and working on the “next big thing.”

Though I’m calling this my “secret non-fiction project” many of you have probably already guessed the topic, and I’ll do a more formal reveal in a couple of weeks once I’ve got something cool like a cover to show you. All I can say at the moment is that I in large part have you, the blogging community, to thank for this project, and I can say without a doubt that if it weren’t for all if you, this book wouldn’t be written, let alone coming out in 2-2.5 months. So thanks, sincerely.

Word count’s not quite the right metric for completeness on this project (and for technical reasons Word not only can’t give me an accurate word count but has thrown up its hands on my spelling and grammar. The reason for this will become apparent shortly). For now I can say that maybe 60-70% of illustrations are complete, all technical aspects are drafted, and 60-70% formatted, and I’m two-thirds of the way through drafting chapter 3 of 6. Chapter 1 was by far the longest, and Chapter 6 will probably be the shortest, though I do have various appendices, prefaces, and other things to complete as well. I’m taking Friday off to another full-time writing day, my third so far, and each has been glorious.

One last thing, after this project releases I’m hoping to take some crunch time to do a last revision on my first-second novel, Surreality. I’m tentatively projecting a release date of January – February 2013 (I’ll have a better idea once I get my hands on it again). The snippet from the awards post a couple of months ago came from this work, and I think its high time I shared it with all of you. Then its back to DM revisions and looking for publishers, and who knows what else (NaNo anyone?)

(Additional Note: AGFV will post next week. I know technically tomorrow is the third Thursday of the month, but I’m usually thinking of a date more like the 21st and I want to have something great for you guys, any suggestions you might have are always welcome in the comments).

Leave a comment

Filed under Books + Publishing, Internal Debate 42, Writing, Writing Goals

3 Ways To Say I Love You (In Code)

Example 1:

#include <iostream>
#include <cstdlib>

using namespace std;

int main() {
  int two;
  two = 1;
  while(two == 1) {
    cout << "I love you little red haired girl\n";
  }
}

Example 2:

#include <iostream>
#include <cstdlib>

using namespace std;

void myLoveGrowsDeeper(int lvl);

int main() {
  int lvl = 1;
  cout << "My love grows deeper";
  myLoveGrowsDeeper(lvl);
  cout << " every day." << endl;
}

void myLoveGrowsDeeper(int lvl) {
  if(lvl == 99) {
    return;
  }
  myLoveGrowsDeeper(lvl+1);
  cout << " and deeper ";
}

Example 3 (Turtle Commands, Pixels, Degrees):

LEFT 45
FORWARD 100
REPEAT 180
  FORWARD PI/2
  LEFT 1
RIGHT 90
REPEAT 180
  FORWARD PI/2
  LEFT 1
FORWARD 100





2 Comments

Filed under Trube On Tech