Gumming up the works of the gallery.

If you're having trouble using Context Free or don't understand the language, ask for help here.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
User avatar
solsword
Posts: 1
Joined: Fri Oct 09, 2009 8:01 pm
Location: Santa Cruz, CA
Contact:

Gumming up the works of the gallery.

Post by solsword »

So... I just posted my first two creations, and I've got another one that I'd like to post. However, I also noticed that on the gallery page, the entire code of the cfdg file gets posted, and since I'm using macros to generate my cfdg files, my 100+ line files make for a lot of scrolling. My most recent piece, which I'm pretty proud of, is 800+ lines of code after macro expansions (from 112). I'm wondering what the preferred method of dealing with this is. I don't want to make the 'last 5' gallery page endless, but I do want to share my source code. I could share the pre-macro version, but then other people wouldn't be able to run it without additional setup. I also ran into issues with the gallery not liking my unexpanded file between

Code: Select all

 tags; probably some character combination that I use that it doesn't like. I'm a bit worried that the problem will be nastier when the code in the cfdg file (which gets onto the page via a file upload, rather than a text box, so it might not be caught when it should be), although I haven't tried it yet.

Anyways, just wanted to hear opinions. I've got my own webspace where I can post my creations if that's neater... or maybe there's an easy way to make the code visibility optional (another forum I frequent has [spoiler] tags, although putting them around the uploaded file might be something an admin would have to do).

On an unrelated note: What's the philosophy of the CF community regarding context? Is it cheating to add context and that's frowned upon (some of my macros exist for exactly that reason: to add context), or is context something that would be nice if it were possible, but simple isn't at the moment? I'm a bit torn about this. On the one hand, I appreciate CF as a unique art medium, and adding context would take away some of that uniqueness. On the other hand, the lack of context makes CF a lot less useful as a generalized art tool, even though in many ways it's one of the best tools that I've seen for generating art: it's simple to use and produces nice clean images in any desired resolution. Also, there's almost no overhead of coding between you and the canvas, unlike many programming environments for art.
cfdg + mm + mogrify = win/cheating

User avatar
kipling
Posts: 91
Joined: Wed Jun 18, 2008 2:36 am

code length

Post by kipling »

I don't think there are any limits on size of CF code. Whatever it is, it is probably quite small in kilobytes compared to other things clogging the internet in general, or the server in particular.

The thing I would advise is to see if you find some way of using the capabilities of the CF language itself rather than the capabilities of your preprocessor. From looking at your designs (which I like) you have been thinking of them as a functional programmer: telling CF what to do to make each part of your carefully planned image. My approach often starts this way, with an idea of what the image will look like, but then I try to get by with as few rules as possible. ... and you need to be prepared to be pleasantly surprised when CF does something different!

Anyway, this is usually a puzzle that I enjoy solving.

There are a lot of tricks you can use to get variation: the main thing to make best use of is CF's in-built randomness, coming from its random selection of rules (as you have used). For instance, in your turf design, you have a whole pile of rules for coding different random curved blades of grass, which you have carefully encoded as splines.

Another way of getting a similar result is to use far fewer blades and to add some randomness to their geometry putting some "geometry modifiers" in the pipeline between your start rule and the actual drawing rules.
Here is a very quick proof of concept of this - a bit rough compared to yours, but I haven't spent much time tweaking.

Code: Select all

startshape crescentRow

background { h 140 sat 0.8 b -0.5 }

rule crescentRow { 100 * { x 0.04 } crescentBlade {} }

rule crescentBlade{ CB{}}
rule crescentBlade{ CB{ f 90} }

rule CB {CB{s 1 1.02}}
rule CB {CB{s 1 0.98}}
rule CB {CB{s 1.02 1}}
rule CB {CB{s 0.98 1}}
rule CB {CB{skew 1 0 }}
rule CB {CB{skew -1 0 }}
rule CB 0.1{payload{}}

rule payload{ONE{}}
rule payload{TWO{}}
rule payload{THREE{}}

rule ONE{
	SQUARE { s 0.1 0.02 y .01}
	ONE { y 0.01 s 0.98 r .2}
	}

rule TWO{
	SQUARE { s 0.1 0.02 y .01 }
	TWO { y 0.01 s 0.98 r .3}
	}

rule THREE{
	SQUARE { s 0.1 0.02 y .01 }
	THREE { y 0.01 s 0.98 r .4}
	}
So I have only encoded three different blades, using simple spirals (using splines is also OK here, but IMO harder to get right), but these are not used directly. Instead they may first be flipped left/right, then scaled up and/or down a few times, skewed a bit left or right, before finally being drawn. The design "chicken & egg" used exactly this process. There are other ways of exploiting rules for randomness: have a look at the tutorials in the wiki for some ideas, and pull apart some gallery designs.

Regarding macro preprocessors, one of the things that can be a little tiresome in CF is to encode designs where many variations of the same rule are necessary (e.g. ONE, TWO, THREE above) or where there is one numeric constant that needs to be used in a few places. Both of these can be handled easily by a decent pre-processor. However, it could turn CF into a language which encourages you to list every item that is drawn, which would be a pity. If you have a good macro solution that takes the middle ground on this, maybe you could share it. Pull up a homepage on the documentation wiki and start explaining what you have done. If it is a really good preprocessor, we can lobby the devs to include it.

Post Reply