newbie "is there an easier way to do this?"

If you have a design you're proud of, share the cfdg file here. It's also a good place to ask for feedback and collaborate.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
AcroTiger
Posts: 1
Joined: Fri Jul 20, 2007 2:18 pm

newbie "is there an easier way to do this?"

Post by AcroTiger »

Is it possible to shorten my code?

Sorry, but I don't know how to post an image, and this code takes a few minutes to parse on my PC...

Code: Select all

/*
	Cathedral Glass
	Mark Baldwin
	cathedralglass.cfdg
*/

startshape CROSS

background { b -1 }

rule CROSS {
	6* { r 60 } BOXES {}
}

rule BOXES {
	BOX5 {}
	WHIRL4 {}
	WHIRL4 { r 90 }
}

rule WHIRL4 {
	WHIRL3 {}
	WHIRL3 { flip 90 }
}

rule WHIRL3 {
	WHIRL2 {}
	WHIRL2 { flip 180 }
}

rule WHIRL2 {
	WHIRL1 {}
	WHIRL2 { y 0.95 s 0.9 r -2 }
}

rule WHIRL1 {
	CIRCLE { s 2 hue 220 sat 1 b 0.5 }
	CIRCLE { s 1.95 hue 190 sat 0.5 b 1 }
	WHIRL1 { s 1 0.8 }
}

rule BOX5 {
	BOX4 {}
	BOX5 { flip 45 s 0.9 }
}

rule BOX4 {
	BOX3 {}
	BOX3 { flip 90 }
}

rule BOX3 {
	BOX2 {}
	BOX2 { flip 180 }
}

rule BOX2 {
	BOX1 {}
	BOX2 { y 0.95 s 0.9 r -2 }
}

rule BOX1 {
	SQUARE { hue 0 sat 1 b 0.5 }
	SQUARE { s 0.95 hue 50 sat 0.5 b 1 }
	BOX1 { s 0.9 r 5 }
}

User avatar
LazyMoon
Posts: 20
Joined: Sun Aug 13, 2006 2:52 am
Location: Adelaide, Australia
Contact:

Post by LazyMoon »

There is in fact an easier way to do it. I specifically looked for areas of your code that can be condensed by removing unnecessary rules. This was what I managed to develop:

Code: Select all

startshape CROSS
background {b -1}

rule CROSS {
	6*[r 60] BOXES[]
	12*[r 30] WHIRL[]
	12*[r 30] WHIRL[flip 180]
}
rule WHIRL {
	WINSIDE[]
	WHIRL[y 0.95 s 0.9 r -2]
}
rule WINSIDE{
	CIRCLE[s 2 hue 220 sat 1 b 0.5]
	CIRCLE[s 1.95 hue 190 sat 0.5 b 1]
	WINSIDE[s 1 0.8]
}
rule BOXES {
	BOXES2[]
	BOXES2[flip 180]
	BOXES2[flip 90]
	BOXES2[flip 270]
	BOXES[flip 45 s 0.9]
}
rule BOXES2 {
	BOX[]
	BOXES2[y 0.95 s 0.9 r -2]
}
rule BOX {
	SQUARE[hue 0 sat 1 b 0.5]
	SQUARE[s 0.95 hue 50 sat 0.5 b 1]
	BOX[s 0.9 r 5]
}
The slight downside is that, due to the order of the statements, the colours of the design are slightly different. Personally I prefer the look of the optimized version over the original :D

I just realized, I could have further condensed:

Code: Select all

	BOXES2[]
	BOXES2[flip 180]
	BOXES2[flip 90]
	BOXES2[flip 270]
Hopefully it wont make a difference. :roll:

Either way, here is a comparison between the original and my optimized code:

Original
Image
Optimized
Image

Hope this helps :wink:
"Bound By Reason, We Are Free In Our Imagination"
View My CDFG Gallery

Post Reply