The site uses cookies that you may not want. Continued use means acceptance. For more information see our privacy policy.

Fun with Context Free

Math is a tool that creates order and chaos in equal (or was it inequal?) measure.

Context Free Art is a simple art-generation context-free language that uses recursion (among other things) to generate images (and videos). I recently saw a post about it, and I decided to try it out. Then I found a folder in my files from 2013 where I had previously come across it and forgotten all about it.

While more suited to the abstract, it’s possible to create more traditional art with it, as seen in two of the four examples at the bottom.

Here is a sample input to the program:

// Sample input
// two slashes make a comment

// command to build:
// cfdg -s 1920x1080 -m 1000000 sample.cfdg sample.png

// cfdg the command
// -s set size to 1080p
// -m set the maximum number of shapes; helps in case of too much recursion
// [file].cfdg the input file
// [file].png the output image

// Required to kick things off.
startshape Sample

// Make a default background color (random)
CF::Background = [b rand(-0.5,-0.25) sat rand(0.25,0.75) h randint(360)]
// b is brightness; sat is saturation; h is hue

shape Sample {
    SQUARE [s 100 x -200]
    CIRCLE [s 100]
    TRIANGLE [s 100 x 200]
}

// s is size; x is horizontal position

There are three basic shapes available. Can you guess what they are?

From left, on a pink background: a black square, a black circle, and a black triangle.

And you can make your own shapes, using path declarations:

path ZA {
    MOVETO(-0.5, 0)
    LINETO(0, 1)
    LINETO(0.5, 0)
    ARCTO(-0.5, 0, -1)
    CLOSEPOLY()
    // STROKE()[]
    FILL() []
}

This example path creates a piece of pizza! Notice it has STROKE commented out. If you want, you can make outlined shapes using that.

From left, on a brown background: a white pizza slice shape, a black pizza slice outline, and a white pizza slice shape with a black outline.

Github: MtnViewJohn: context-free: Wiki has most of the details on how to use the tool, though you can also look at the gallery of the official website (linked above), where users have provided samples that include their source code.


Anyway, just a short writeup. Here’s some pictures I made with it:

On a green background, a cone-looking tornado kind of thing with colors shifting from green to yellow to pink to purple.
A misshapen earth-like figure with water, land, and clouds, seen on a space-like background.
A sky with clouds and sun above dirt filled with plants and a few trees.
A psychedelic swirl of green, yellow, orange, red, pink, purple, and blue.

Random Bad Ideas I Won’t Use

These ideas are worth what you pay for them. And, yeah, I technically used them for a blog post.

I try to be a good steward of the random thoughts that pop into my head, but most times they are fleeting and flimsy and won’t bear any weight for a larger idea. So here’s some of them, with notes where appropriate.

(Metaphor) addiction cf. electric shock contractions

This was the idea that addiction could be seen similarly to how the body reacts to electric shock. When you shock muscle, it involuntarily contracts. For example, the child sticking the key in the electrical outlet cannot let go, because the hand muscles are contracting on the key.

Addiction seems similar, in that the addiction itself causes the grasp for more of the substance or experience, so that the victim cannot easily fix the problem themselves.

Snotheads/sneezeheads/the God-blessed: folks that constantly make themselves sneeze (powder, feathers, bright light, etc.) in order to get off on the sneeze feeling.

The idea that there could be people who liked sneezing too much. Might be real, haven’t checked. Pretty sure this one came to mind when I read Infinite Jest, because of that stuff about the Entertainment.

Could be expanded to a War on Drugs type thing where there are special cops that try to crack down on the sneezers.

(Another one I’d written down at a different time, but could be folded in: “The snottish play: out out, damn snot” Perhaps a whole thing based on Macbeth?)

even if you had a magic bullet, you’d need a magic gun to shoot it.

This reminds of the notion that after every crisis (incl., e.g., the recent mass shootings) we’re inundated with all sorts of smart and dumb ideas, none of which get to the root cause: our inability to proceed with attempting any serious policy solution.

We might have the answer to any given problem, but we lack the ability to execute it. We may very well have the bullet, but not the gun to fire it.

Afterlife awards for mundane achievements (best at tying shoes, etc.)

There’s probably some stuff you’re really good at, even if it’s not important at all. You’re really good at keeping your pockets lint-free. Or you’ve mastered the art of getting as much toothpaste out of the tube as possible. Perhaps when you die and go on to whatever’s next, they could hand out awards for those things, to recognize your achievement.

“Going by the name, the Food and Drug Administration sounds like a pretty happening place.” or “Food, Drugs, and Cosmetics? Sounds like a weekend trip to the mall.”

Kind of weird how mall is now a wasteland word in many parts of the country.

“Like my drill sergeant always said . . .” “You were in the service?” “Naw, they kicked me out first day of boot camp. Right after Sarge said that shit.”

Eh? Feels derivative. Probably a line just like that in some comedy somewhere.

Instead of “pea-sized amount” → Fish eye amount

Another toothpaste-related thought. Many of these do come while I’m brushing my teeth. There was another I don’t remember if I wrote down. On the back it says, “Children 2 or under ask your dentist,” so you dial the phone and have the two-year-old ask the dentist if they should brush their toofs.

Broccoli-Os: cereal that tastes like broccoli to adults, but tastes great to kids.

If there’s some chemical short circuit in the tongue as you age, to make it taste like a healthfood, but kids think it’s real nummy. Would probably have a marketing problem, as if you appeal to kids, the parents will catch on, and if you appeal to adults, the kids might not eat it out of spite.

Can’t invite cops/FBI in because they might be vampires.

“Are you a vampire? You know you have to tell me if you’re a vampire.” Also probably derivative, given how much vampire stuff has been done. Maybe go the other way and have a cop who is a vampire but still tries to be a cop. Even with a warrant, she can’t enter peoples’ homes without being invited, so she’s always getting in trouble. “You had a warrant, what was the problem?!”

Sperm bank specializing in matching women who have had plastic surgery with donors so their kids will actually look like them (possibly using police DNA DBs)

I think I might have tried to use this in an unpublished story. Seems like it could be practical, though, for women who really don’t want anyone to know they got a nose job. They’re doing all sorts of stuff to recreate how unknown crime victims and mummies would have looked, so it’s probably not as far-fetched as it sounds. The main question is whether even (non-defect-or-injury-correcting) plastic surgery patients would be that vain.


Okay. Enough. I’ll run out of bad ideas if I keep going, and then where will I be?