Page 1 of 1

Challenge: equilateral triangle with smallest shape count

Posted: Sat May 07, 2005 1:05 pm
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 }
}

Posted: Mon May 09, 2005 11:19 am
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}
}

Posted: Fri May 13, 2005 4:33 am
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:

Posted: Fri May 13, 2005 5:50 am
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.

Posted: Fri May 13, 2005 6:43 am
by bigelectricat
oops. i totally forgot about circles. oh well... :?

Posted: Fri May 13, 2005 6:46 am
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.

Posted: Fri May 13, 2005 7:14 am
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.

:|

Equilateral Triangle

Posted: Sat May 14, 2005 10:16 pm
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 }
}

My Triangle

Posted: Sun May 15, 2005 6:58 am
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.

Anti-aliasing and little lines

Posted: Tue May 17, 2005 9:15 am
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.

Posted: Sat Jun 11, 2005 5:58 am
by aqua_scummm
wait, not yet :(

Posted: Sat Jun 11, 2005 9:10 am
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.

Posted: Sun Jun 12, 2005 12:10 am
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 :(