Challenge: equilateral triangle with smallest shape count

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
User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Challenge: equilateral triangle with smallest shape count

Post by MtnViewJohn »

Although I think we should have right and equilateral triangles as terminal shapes, until then I want to try to create a triangle from circles and squares with the smallest shape count.

I throw down a challenge to all CFDG users to generate an equilateral triangle in a 500x500 canvas the uses the smallest number of shapes. I'll start with my entry, with a shape count of 51:

Code: Select all

startshape triangle

rule rightarm {
	SQUARE { size 1.25 y +0.125}
	rightarm { x +0.75 y -0.25 size 0.5}
}

rule start_rightarm {
	rightarm { x +0.75 y -0.25 size 0.5}
}

rule leftarm {
	SQUARE { size 1.25 y +0.125}
	leftarm { x -0.75 y -0.25 size 0.5}
}

rule start_leftarm {
	leftarm { x -0.75 y -0.25 size 0.5 }
}

rule arm {
	SQUARE {y -0.36666666}
	start_rightarm{y -0.36666666}
	start_leftarm { y -0.36666666}
}

rule triangle {
	arm { }
	arm { r 120 }
	arm { r -120 }
}

David Spitzley
Posts: 21
Joined: Fri May 06, 2005 10:01 am

Post by David Spitzley »

Ok, these aren't all that efficient, but I've got 30, 45 and 60-degree right triangles (using the top angle for naming), and an equilateral, all with a unit length for the longest non-hypoteneuse side.

Code: Select all

startshape BLOB

rule BLOB{

	r30_triangle{}
	r45_triangle{x 1}
	r60_triangle{x 2}
	eq_triangle{x 3}
}

rule r30_triangle{
	SQUARE{s 0.366 x -0.315 y -0.315}
	r30_triangle{x 0.05 y -0.3159 s 0.366}
	r30_triangle{y 0.183 x -0.1823 s 0.634}
}
rule r45_triangle{
	SQUARE{s .5 x -0.25 y -0.25}
	r45_triangle{y .25 x -0.25 s 0.5}
	r45_triangle{x .25 y -0.25 s 0.5}
}
rule r60_triangle{
	SQUARE{s 0.366 x -0.315 y -0.315}
	r60_triangle{y 0.05 x -0.3159 s 0.366}
	r60_triangle{x 0.183 y -0.1823 s 0.634}
}

rule eq_triangle{
	SQUARE{s .4675 y -.26}
	r30_triangle{x .4667 y -.26 s .4675}
	r60_triangle{x -.4667 y -.26 s .4675 r 90}
	eq_triangle{y .2 s .46}
}

bigelectricat
Posts: 19
Joined: Fri May 06, 2005 8:43 am

Post by bigelectricat »

Code: Select all

startshape tiny

rule tiny {


    shape1 { x 0 y 0 }

}

rule shape1 {

    SQUARE { x 0 y 3.6 s 8 b 0}
    SQUARE { x -5 y 5 s 10 r -120 b 1 }
    SQUARE { x 5 y 5 s 10 r 120 b 1 }

}
i know this might be cheating but i made one using 3 shapes. :lol:

David Spitzley
Posts: 21
Joined: Fri May 06, 2005 10:01 am

Post by David Spitzley »

Unfortunately, if you replace tiny with

rule tiny {
shape1 { x 0 y 0 }
CIRCLE {x 7 s 5}
}

you can see that masking with white squares has some undesirable consequences when you combine the resulting triangle with other shapes.

bigelectricat
Posts: 19
Joined: Fri May 06, 2005 8:43 am

Post by bigelectricat »

oops. i totally forgot about circles. oh well... :?

David Spitzley
Posts: 21
Joined: Fri May 06, 2005 10:01 am

Post by David Spitzley »

Well, it isn't just circles. The triangle you designed essentially has two wings of white space which can and will overlap other shapes, as with the circle in the example, and this will typically be undesirable.

bigelectricat
Posts: 19
Joined: Fri May 06, 2005 8:43 am

Post by bigelectricat »

hmm... what if there was a way to make a shape transparent to one and opaque to another? like maybe the negative white squares are opaque to the black square that they are subracting from but are transparent to the next group of squares? a.k.a. masking with alpha channels. it might be less intensive than repeating a group of 51 squares that make one triangle to create a more complex pattern.

im not a programmer so dont think i know how to do this. just throwing some ideas out there.

:|

buckyboy314
Posts: 8
Joined: Wed May 11, 2005 11:30 am
Contact:

Equilateral Triangle

Post by buckyboy314 »

Try THIS one on for size:
(Render it without antialiasing...It lines up so well that antialiasing makes little lines.)

startshape TRIANGLE
rule TRIANGLE{
TRI{}
TRI{r 120}
TRI{r -120}
}
rule TRI{
SQUARE{x -0.183013 y 0.683013 r -30 }
SQUARE{x 0.183013 y 0.683013 r 30 }
TRI{y 1.1547 s 0.42265 }
}
-Dan

buckyboy314
Posts: 8
Joined: Wed May 11, 2005 11:30 am
Contact:

My Triangle

Post by buckyboy314 »

By the way, my design comes in at 42 shapes. Not to mention the program I wrote to generate it can make ANY triangle.
-Dan

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Anti-aliasing and little lines

Post by MtnViewJohn »

In the upcoming beta of Context Free the little lines between squares will go away. Mark and I have created a compliance test for the platform-specific drawing code to make sure that the primitives look the same on all platforms. We tweaked the anti-aliased drawing code to remove lines between abutted squares. You won't have to put SQUARE {s 1.01} in your rules any more.

aqua_scummm
Posts: 17
Joined: Sat Jun 11, 2005 5:44 am
Location: Redwood City, CA
Contact:

Post by aqua_scummm »

wait, not yet :(

User avatar
mtnviewmark
Site Admin
Posts: 81
Joined: Wed May 04, 2005 12:46 pm
Location: Mountain View, CA
Contact:

Post by mtnviewmark »

aqua_scummm wrote:wait, not yet
Uhm, what did you mean? The versions since 1.0 have had this tweak in them. Is it that you like the way the drawing code currently works and don't want to see it change? If so, all's cool.
I'm the "m" in "mtree.cfdg"

aqua_scummm
Posts: 17
Joined: Sat Jun 11, 2005 5:44 am
Location: Redwood City, CA
Contact:

Post by aqua_scummm »

Sorry, it was super early (about 5 am). Thought I had a really good one, but its not equilateral... yet. So I edited it.

Apologies, I was tired :(

Post Reply