startshape realStart rule realStart { start { x 2 } } background { b -1 } rule start { terminal4 { r 12 } } rule start { terminal1 { r 12 } } rule start { terminal4 { r 12 } } rule start { terminal4 { r 12 } } rule start .05 { terminal2 { r 12 } } rule terminal4 { SQUARE { b 0.50 s .055 sat 0.40 hue 95 } SQUARE { b 1 s .055 a -.8 } train { x .06 } train { r 90 y .06 } train { r 180 x -.06 } train { r 270 y -.06 } } rule terminal2 2 { SQUARE { b 1 s .055 a -.85 } train { r 90 y .06 } train { r 270 y -.06 } } rule terminal2 1 { SQUARE { b 1 s .055 a -.8 } train { x .06 } train { r 90 y .06 } } rule terminal2 1 { SQUARE { b 1 s .055 a -.85 } train { x.06 } train { r 270 y -.06 } } rule terminal1 { CIRCLE { b 1 s .055 a -.9 } train { r 90 y .06 } } rule terminal1 { CIRCLE { b 1 s .055 a -.9 } train { r -90 y -.06 } } rule train 1 { CIRCLE { b 1 s .045 a -.9 } train { x .06 } } rule train 2 { terminal1 { } } rule train .02 { terminal2 { } } rule train .005 { terminal4 { } } rule train .03 { CIRCLE { b 1 s .03 a -.9 r -95 } }

Keith's Blog

A teen's .net musings

Context Free World

Posted on June 4, 2010 at 5:44 PM

I have been dabbing in context free again and have created some new works that I would like to share. The first of a few that I will be posting on is a work on the world. I got the original idea from a project that a guy made called It's a Small World After All I thought it was unique and so I elaborated on it. I saw that it did a really good job of suggesting a world, so I decided to give it three new things and as an added challenge I forced myself not to look at his code at all and only replicate the result. The code I came up with was this:

startshape start

rule start {
	360 * { x 1 r 1 } {
		SQUARE { }
		building { y 1 }
	}
}

rule building 1.5 {
	SQUARE{}
	building{ y 1 }
}

rule building { 
	SQUARE{}
}

This didn’t quite turn out as I expected as shown here!

Fail World

Not only were the buildings pointing down but they were also too small so I then generated this new code to fit the required criteria.

startshape start

rule start {
	180 * { x 1 r -2 } {
		SQUARE { }
		building { y 1 }
	}
}

rule building 1.5 {
	SQUARE{}
	building{ y 1 }
}

rule building { 
	SQUARE{}
}

The fixed image was this:

Not so Fail World

Now the buildings were better and were facing up like they should and all was good in the world (pun intended) at least until meg came in! She came and said it was cool and that what it REALLY needed was some UFOs. I sighed and complied because I had nothing better to do and created some UFO code.

startshape ufo

rule ufo {
	CIRCLE{  }
	SQUARE{ b 1 y –.25 s 1 .5 }
	CIRCLE{ s 1.5 .5 }
}

Which then was used to make this Context-Free-Planet-Terrorizing-Machine.

UFO

Now the only trouble was getting it on top of the buildings with out it running into the top of them. This was quickly remedied by adding another building finisher that had a UFO 10 units above it.

startshape start

rule start {
	180 * { x 1 r -2 } {
		SQUARE { }
		building { y 1 }
	}
}

rule building 1.5 {
	SQUARE{}
	building{ y 1 }
}

rule building { 
	SQUARE{}
}

rule building {
	SQUARE{}
	ufo{ y 10 }
}

rule ufo {
	CIRCLE{  }
	SQUARE{ b 1 y -.25 s 1 .5}
	CIRCLE{ s 1.5 .5 }
}

This created a slightly different problem for the inhabitants of small-vill.

UFO Apocolypse

The poor inhabitants were now being over run by a UFO apocalypse. I triumphantly marched over to my slave driver of a sister and showed her the new calamity that she had ordered upon my poor creation. And of coarse she was not pleased. Sigh now she wanted there only to be one or two of the UFOs so that all of my people didn’t die at once but took a while first. So now I added a lower value to the randomness of the UFO invasion.

startshape start

rule start {
	180 * { x 1 r -2 } {
		SQUARE { }
		building { y 1 }
	}
}

rule building 1.5 {
	SQUARE{}
	building{ y 1 }
}

rule building { 
	SQUARE{}
}

rule building .03 {
	SQUARE{}
	ufo{ y 10 }
}

rule ufo {
	CIRCLE{  }
	SQUARE{ b 1 y -.25 s 1 .5}
	CIRCLE{ s 1.5 .5 }
}

The new world now only had a few enemies from the sky.

UFO Apocolypse 2

When showed the new picture my all knowing sister nodded, an said that it was good. She then ordered my new born planet into a sudden onslaught of color because “ it was to boring with out it. “ So I decided to do two things to add a little bit of color to the small little world. First I would make the sky be a nice blue and second I would add some green to the center. The first job was easy and done with a simple background directive, but the second was a little harder. I wanted the color to be around the whole planet and I wanted it to be a gradual shading into the center not a harsh one. So I decided to make every section of the planet send of a tendril of color into the center which would gradually shade from bright green into a brownish color. The only problem with just changing that was that I needed to make the erasing squares under each of the UFOs become the same color. So I did and came up with this: 

startshape start

background{ hue 200 sat 1 }

rule start {
	180 * { x 1 r -2 } {
		SQUARE { }
		building { y 1 }
		tendril{ y -1 h 107.31 sat 0.8962 b 1.0000 }
	}
}

rule building 1.5 {
	SQUARE{}
	building{ y 1 }
}

rule building { 
	SQUARE{}
}

rule building .03 {
	SQUARE{}
	ufo{ y 10 }
}

rule ufo {
	CIRCLE{  }
	SQUARE{ b 1 y -.25 s 1 .5 hue 200 sat 1 }
	CIRCLE{ s 1.5 .5 }
}

rule tendril {
	26 * { a -0.06 hue -2  y -1.1 b -0.02` z 1} {SQUARE{}}
}

This produced a colorful new habitat for my imaginary subjects.

Colorful planet

All this was shown to the royal majesty and wonder of wonders she was still not happy. So now she wanted a planet that was more green than this one. I protested saying that this was as green as it could get but she said “Not that kind of green, silly! You need less buildings and more trees.” I slowly sulked back to my corner and came up with a clever little tree design.

startshape tree

rule tree {
	SQUARE{s .05 .1 h 33.69 sat 1.0000 b 0.7017 }
	TRIANGLE{y .05 s .5 .25 h 117.90 sat 1.0000 b 0.7017 }
	TRIANGLE{ y .15 s .4 .25 h 117.90 sat 1.0000 b 0.7017 }
	TRIANGLE{ y .25 s .3 .25 h 117.90 sat 1.0000 b 0.7017 }
}

tree

 

THIS was then placed on top of the new terrain type.  The only problem is that the project that I had before was created with only one terrain in mind and the terrain really needs to be in sections that are more then completely random. I decided that the sections would be 5 squares long and would be random after that. So I came up with this new code to create the circle.

startshape start

background{ hue 200 sat 1 }

rule start {
	36 * {x 5 r -10} {
		terrainSection {r 5 }
	}
}

rule terrainSection {
	5 * {r -2 x 1}	{
		SQUARE{}
		building{ y 1 }
		tendril{ y -1 h 107.31 sat 0.8962 b 1.0000 }
	}
}

rule terrainSection {
	5 * {r -2 x 1}	{
		SQUARE{}
		tree{ y 1 s 7 z 100000}
		tendril{ y -1 h 107.31 sat 0.8962 b 1.0000 }
	}
}

rule building 1.5 {
	SQUARE{}
	building{ y 1 }
}

rule building { 
	SQUARE{}
}

rule building .03 {
	SQUARE{}
	ufo{ y 10 }
}

rule ufo {
	CIRCLE{  }
	SQUARE{ b 1 y -.25 s 1 .5 hue 200 sat 1 }
	CIRCLE{ s 1.5 .5 }
}

rule tendril {
	26 * { a -0.06 hue -2  y -1.1 b -0.02` z 1} {SQUARE{}}
}

rule tree {
	SQUARE{s .05 .1 h 33.69 sat 1.0000 b 0.7017 }
	TRIANGLE{y .05 s .5 .25 h 117.90 sat 1.0000 b 0.7017 }
	TRIANGLE{ y .15 s .4 .25 h 117.90 sat 1.0000 b 0.7017 }
	TRIANGLE{ y .25 s .3 .25 h 117.90 sat 1.0000 b 0.7017 }
}

rule tree { }

As you can see, I added the tree code that I had come up with along with the new world creation code. The way it works is I make the new circle with a larger x and r value in order to give room for each piece of terrain. Then I make a new rule that decides which terrain to use and then creates it. The last thing that I had to do was add a blank tree rule so that the forest would look semi random. The resulting picture is this:

planet with forest

I then showed this to my sis and of coarse, once again she wanted more. She said that trees do not grow on the same stuff that buildings grow on and that if they were real trees they needed dirt not artificial stuff. So I then added coloring to the crust of my planet where it had not been colonized. At this point I had spent quite a bit of time creating this piece and I showed the fruits of my labor to my dad. He looked at it with a critical eye and said that the thing that it really needed was a new terrain that included water. So I set about to implement the new requests. All I needed to do the water was to create a new terrain method that had blue squares instead of the original ones.

startshape start

background{ hue 200 sat 1 }

rule start {
	36 * {x 5 r -10} {
		terrainSection {r 5 }
	}
}

rule terrainSection {
	5 * {r -2 x 1}	{
		SQUARE{}
		building{ y 1 }
		tendril{ y -1 h 107.31 sat 0.8962 b 1.0000 }
	}
}

rule terrainSection {
	5 * {r -2 x 1}	{
		SQUARE{ h 29.74 sat 1.0000 b 0.5580 }
		tree{ y 1 s 7 z 100000}
		tendril{ y -1 h 107.31 sat 0.8962 b 1 }
	}
}

rule terrainSection {
	5* {r -2 x 1} {
		SQUARE{ h 238.63 sat 1.0000 b 0.6133 y -.5 z 100000 }
		tendril{ y -1 h 107.31 sat 0.8962 b 1 }
	}
}

rule building 1.5 {
	SQUARE{}
	building{ y 1 }
}

rule building { 
	SQUARE{}
}

rule building .03 {
	SQUARE{}
	ufo{ y 10 }
}

rule ufo {
	CIRCLE{  }
	SQUARE{ b 1 y -.25 s 1 .5 hue 200 sat 1 }
	CIRCLE{ s 1.5 .5 }
}

rule tendril {
	26 * { a -0.06 hue -2  y -1.1 b -0.02` z 1} {SQUARE{}}
}

rule tree {
	SQUARE{s .05 .1 h 33.69 sat 1.0000 b 0.7017 }
	TRIANGLE{y .05 s .5 .25 h 117.90 sat 1.0000 b 0.7017 }
	TRIANGLE{ y .15 s .4 .25 h 117.90 sat 1.0000 b 0.7017 }
	TRIANGLE{ y .25 s .3 .25 h 117.90 sat 1.0000 b 0.7017 }
}

rule tree { }

Here I created the colors for the new terrain and I decided to make the more natural terrains become a little more round or natural looking, so I decided to make their draw be in circles instead of squares. I also doubled the frequency of the circles so that it wouldn’t be as bumpy. The resulting code was now:

startshape start

background{ hue 200 sat 1 }

rule start {
	36 * {x 5 r -10} {
		terrainSection {r 5 }
	}
}

rule terrainSection {
	5 * {r -2 x 1}	{
		SQUARE{}
		building{ y 1 }
		tendril{ y -1 h 107.31 sat 0.8962 b 1.0000 }
	}
}

rule terrainSection {
	5 * {r -2 x 1}	{
		CIRCLE{ h 29.74 sat 1.0000 b 0.5580 }
		CIRCLE{ h 29.74 sat 1.0000 b 0.5580 x .5 }
		tree{ y 1 s 7 z 100000}
		tendril{ y -1 h 107.31 sat 0.8962 b 1 }
	}
}

rule terrainSection {
	5* {r -2 x 1} {
		CIRCLE{ h 238.63 sat 1.0000 b 0.6133 y -.5 z 100000 }
		CIRCLE{ h 238.63 sat 1.0000 b 0.6133 y -.5 z 100000 x .5 }
		tendril{ y -1 h 107.31 sat 0.8962 b 1 }
	}
}

rule building 1.5 {
	SQUARE{}
	building{ y 1 }
}

rule building { 
	SQUARE{}
}

rule building .03 {
	SQUARE{}
	ufo{ y 10 }
}

rule ufo {
	CIRCLE{  }
	SQUARE{ b 1 y -.25 s 1 .5 hue 200 sat 1 }
	CIRCLE{ s 1.5 .5 }
}

rule tendril {
	26 * { a -0.06 hue -2  y -1.1 b -0.02` z 1} {SQUARE{}}
}

rule tree {
	SQUARE{s .05 .1 h 33.69 sat 1.0000 b 0.7017 }
	TRIANGLE{y .05 s .5 .25 h 117.90 sat 1.0000 b 0.7017 }
	TRIANGLE{ y .15 s .4 .25 h 117.90 sat 1.0000 b 0.7017 }
	TRIANGLE{ y .25 s .3 .25 h 117.90 sat 1.0000 b 0.7017 }
}

rule tree { }

The new picture was now this:

World with water

by now my creation was becoming pretty interesting and I now realized a few things that had happened on accident but seemed to turn out well. First is the fact that the UFOs only appear over the buildings which I didn’t do on purpose but did make sense. Also is the fact that the land with trees wasn’t moved forward to be in front like the water and so it was always behind everything and met nicely at the junction between land and building or land and water. I was trying to come up with some new features for my quickly developing planet and decided to make clouds up in the sky. I had no clue on how to make this new thing and so decided to “borrow” someone else's. I looked and looked and came across a somewhat cartoonish cloud that appeared to fit nicely with the rest of my design. I was trying to understand how it worked but the author of this horrifically created code was not nice enough to give names to his methods that made any sense what so ever. If so I will not show the code here but the picture that was created was this:

cloud 

Now all I had to do was replace the UFOs with the clouds. Once I had clouds I realized that the clouds need an atmosphere and so I added some Circles that change in color from blue fading into black.

startshape planet

background {b -1 }

rule planet {
	sky { z -1000000000000 y -28 x 2}
	world{ }
}

rule world{
	36 * {r -10 x 5} {
		terrainSection {r 5 }
	}
}

rule terrainSection {
	5 * {r -2 x 1}	{
		SQUARE{}
		building{ y 1 }
		tendral{ y -1 h 107.31 sat 0.8962 b 1.0000 }
		cloud{ y 10 s 5 }
	}
}

rule terrainSection {
	5 * {r -2 x 1 } {
		CIRCLE{h 29.74 sat 1.0000 b 0.5580}
		CIRCLE{h 29.74 sat 1.0000 b 0.5580 x .5}
		tree{ y 1 s 7 z 100000}
		tendral{ y -1 h 107.31 sat 0.8962 b 1.0000 }
		cloud{ y 10 s 5 }
	}
}

rule terrainSection {
	5 * {r -2 x 1 } {
		CIRCLE{h 238.63 sat 1.0000 b 0.6133 y -.5 z 100000}
		CIRCLE{h 238.63 sat 1.0000 b 0.6133 y -.5 z 100000 x .5}
		tendral{ y -1 h 107.31 sat 0.8962 b 1.0000 }
		cloud{ y 10 s 5 }
	}
}

rule building 1.5 {
	SQUARE{}
	building{ y 1 }
}

rule building { 
	SQUARE{}
}

rule tendral {
	26 * { a -0.06 hue -2  y -1.1 b -0.02` z 1} {SQUARE{}}
}

rule tree {
	SQUARE{s .05 .1 h 33.69 sat 1.0000 b 0.7017 }
	TRIANGLE{y .05 s .5 .25 h 117.90 sat 1.0000 b 0.7017 }
	TRIANGLE{ y .15 s .4 .25 h 117.90 sat 1.0000 b 0.7017 }
	TRIANGLE{ y .25 s .3 .25 h 117.90 sat 1.0000 b 0.7017 }
}

rule tree { }

rule sky {
	100 * { s .99 b .05 a .1 z 10000  } { CIRCLE{ size 125 hue 200 b 0 sat 1 } }
}

rule cloud {
	formeB{y 1 s .75 z 60}
	inNUAGE{z 30}
	inNUAGE{flip 90}
}

rule cloud 10 {}

rule inNUAGE 3{
	formeB{y .9}
	inNUAGE{x .5 s .8 z -15}
}

rule inNUAGE 3{
	formeB{y .9}
	inNUAGE{x .5 s .6 z -15}
}

rule formeB 15{
	formeA{}
	formeB{s .9 r 73 z -1}
}

rule formeB 15{
	formeA{} 
	formeB{s .9 r 53 z -1}
}

rule formeB {
	formeA{}
	formeB{s .9 r 127 z 15}
}

rule formeA 3{
	CIRCLE {hue 195 sat .3 x -.75}
	INformeA{x -.72 s .99}
}

rule formeA 6{
	CIRCLE {hue 195 sat .3 x -.6}
	INformeA{x -.57 s .99}
}

rule formeA {
	CIRCLE {hue 195 sat .3 x -.3}
	INformeA{x -.27 s .99}
}

rule INformeA 3{
	INformeA{s .99}
}

rule INformeA 3{
	INformeA{x .01}
}

rule INformeA {
	CIRCLE{b 1}
}

As you can see the code is a little different  but mostly is the same. The resulting picture is this:

World4

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading