Wireframe Serpinski

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
aaronstj
Posts: 66
Joined: Wed Jul 06, 2005 11:34 am
Location: Seattle

Wireframe Serpinski

Post by aaronstj »

Here's a wireframe Serpinski's triangle. It includes several recursively defined lines that are useful.

Code: Select all

startshape serpinski

rule serpinski{
	//the sides of the triangle
	line { r 0 y -0.288}
	line { r 120 y 0.144 x .25}
	line { r 240 y 0.144 x -.25 }

	//fill in the corners to make it look neat
	CIRCLE { s 0.015625 y 0.576 }
	CIRCLE { s 0.015625 y -0.288 x .5 }
	CIRCLE { s 0.015625 y -0.288 x -.5 }
	
	serpinski{ y .288 size .5}
	serpinski{ y -0.144 x .25 size .5}
	serpinski{ y -0.144 x -.25 size .5}

}

rule line {
	line64 {}
}

rule line2 {
	SQUARE { x -.25 size .5 }
	SQUARE { x .25 size .5 }
}

rule line4 {
	line2 { x -.25 size .5 }
	line2 { x .25 size .5 }
}

rule line8 {
	line4 { x -.25 size .5 }
	line4 { x .25 size .5 }
}

rule line16 {
	line8 { x -.25 size .5 }
	line8 { x .25 size .5 }
}

rule line32 {
	line16 { x -.25 size .5 }
	line16 { x .25 size .5 }
}

rule line64 {
	line32 { x -.25 size .5 }
	line32 { x .25 size .5 }
}

User avatar
chris
Site Admin
Posts: 72
Joined: Wed May 04, 2005 10:57 am
Location: New York, NY
Contact:

Post by chris »

I love that serpinski. Check out how abstract it gets if you put a 10 degree rotation in the recursion... I would say that more than anything I've seen in CFDG, it looks like a hand-drawn piece:

Code: Select all

startshape serpinski 

rule serpinski{ 
   //the sides of the triangle 
   line { r 0 y -0.288} 
   line { r 120 y 0.144 x .25} 
   line { r 240 y 0.144 x -.25 } 

   //fill in the corners to make it look neat 
   CIRCLE { s 0.015625 y 0.576 } 
   CIRCLE { s 0.015625 y -0.288 x .5 } 
   CIRCLE { s 0.015625 y -0.288 x -.5 } 
    
   serpinski{ y .288 size .5 rotate 10} 
   serpinski{ y -0.144 x .25 size .5 rotate -10} 
   serpinski{ y -0.144 x -.25 size .5 rotate 10} 

} 

rule line { 
   line64 {} 
} 

rule line2 { 
   SQUARE { x -.25 size .5 } 
   SQUARE { x .25 size .5 } 
} 

rule line4 { 
   line2 { x -.25 size .5 } 
   line2 { x .25 size .5 } 
} 

rule line8 { 
   line4 { x -.25 size .5 } 
   line4 { x .25 size .5 } 
} 

rule line16 { 
   line8 { x -.25 size .5 } 
   line8 { x .25 size .5 } 
} 

rule line32 { 
   line16 { x -.25 size .5 } 
   line16 { x .25 size .5 } 
} 

rule line64 { 
   line32 { x -.25 size .5 } 
   line32 { x .25 size .5 } 
}
Current Project: I'm creative director of OKCUPID at http://www.okcupid.com

User avatar
chris
Site Admin
Posts: 72
Joined: Wed May 04, 2005 10:57 am
Location: New York, NY
Contact:

Post by chris »

Oh, another variation: I added a random rotation (artist inaccuracy!) to the lines.

Hope my playing with your code isn't too interfering. I just like to play with the CFDG's I really like.

Code: Select all

startshape serpinski 

rule serpinski{ 
   //the sides of the triangle 
   line { r 0 y -0.288} 
   line { r 120 y 0.144 x .25} 
   line { r 240 y 0.144 x -.25 } 

   //fill in the corners to make it look neat 
   CIRCLE { s 0.015625 y 0.576 } 
   CIRCLE { s 0.015625 y -0.288 x .5 } 
   CIRCLE { s 0.015625 y -0.288 x -.5 } 
    
   serpinski{ y .288 size .5 rotate 10} 
   serpinski{ y -0.144 x .25 size .5 rotate -10} 
   serpinski{ y -0.144 x -.25 size .5 rotate 10} 

} 

rule line {
 line { r 1 }
}

rule line {
 line { r -1 }
}

rule line 0.1{ 
   line64 {} 
} 

rule line2 { 
   SQUARE { x -.25 size .5 } 
   SQUARE { x .25 size .5 } 
} 

rule line4 { 
   line2 { x -.25 size .5 } 
   line2 { x .25 size .5 } 
} 

rule line8 { 
   line4 { x -.25 size .5 } 
   line4 { x .25 size .5 } 
} 

rule line16 { 
   line8 { x -.25 size .5 } 
   line8 { x .25 size .5 } 
} 

rule line32 { 
   line16 { x -.25 size .5 } 
   line16 { x .25 size .5 } 
} 

rule line64 { 
   line32 { x -.25 size .5 } 
   line32 { x .25 size .5 } 
}
Current Project: I'm creative director of OKCUPID at http://www.okcupid.com

User avatar
aaronstj
Posts: 66
Joined: Wed Jul 06, 2005 11:34 am
Location: Seattle

Post by aaronstj »

chris wrote: Hope my playing with your code isn't too interfering. I just like to play with the CFDG's I really like.
Oh, please do play. It seems to me that playing with other peroples CFDG's is what this forum is/should be all about. That's how I managed to figure the damn thing out in the first place, anyway :)

User avatar
aaronstj
Posts: 66
Joined: Wed Jul 06, 2005 11:34 am
Location: Seattle

Post by aaronstj »

I finally took a closer look at your source. That's a clever way of picking a random rotation, and you can be sure I'll be using it in the future. :)

Anyway, I took the next logical step and applied a random rotation to the triangles themselves, as well as the lines.

Code: Select all

startshape meta_serpinski

rule meta_serpinski {
	meta_serpinski { r -1}
}

rule meta_serpinski {
	meta_serpinski { r 1 }
}

rule meta_serpinski 0.2 {
	serpinski {}
}

rule serpinski{
   //the sides of the triangle
   line { r 0 y -0.288}
   line { r 120 y 0.144 x .25}
   line { r 240 y 0.144 x -.25 }
   
   meta_serpinski { y .288 size .5 }
   meta_serpinski { y -0.144 x .25 size .5 }
   meta_serpinski { y -0.144 x -.25 size .5 }

}

rule line {
 line { r 1 }
}

rule line {
 line { r -1 }
}

rule line 0.1{
   line64 {}
}

rule line2 {
   SQUARE { x -.25 size .5 }
   SQUARE { x .25 size .5 }
}

rule line4 {
   line2 { x -.25 size .5 }
   line2 { x .25 size .5 }
}

rule line8 {
   line4 { x -.25 size .5 }
   line4 { x .25 size .5 }
}

rule line16 {
   line8 { x -.25 size .5 }
   line8 { x .25 size .5 }
}

rule line32 {
   line16 { x -.25 size .5 }
   line16 { x .25 size .5 }
}

rule line64 {
   line32 { x -.25 size .5 }
   line32 { x .25 size .5 }
} 

User avatar
chris
Site Admin
Posts: 72
Joined: Wed May 04, 2005 10:57 am
Location: New York, NY
Contact:

Post by chris »

oh nice call on rotating the triangles.

That random rotation trick I discovered while making the dance_party.cfdg (it's on this board)... On that one I actually had an object that was a pivot point with a segment attached, with a pivot on the end of that, with another segment attached. It allowed random limbs. It was a pleasing discovery.

You can do something similar for random translations: just have rules for adding or subtracting small values to x and y, with small probability of termination.

cc
Current Project: I'm creative director of OKCUPID at http://www.okcupid.com

phatcat
Posts: 3
Joined: Thu Jul 07, 2005 9:31 pm

slimmed down version

Post by phatcat »


startshape tri_embed

rule arm {
CIRCLE {}
arm {y .2 s .8}
}

rule tri_ol {
arm {}
arm {s .999 b 1}
}

rule tri_embed {
tri_ol {}
tri_embed {x -.43 y -.25 s .5 }
tri_embed {x .43 y -.25 s .5 }
tri_embed {y .5 s .5 }
}


for fun, try commenting out one of the three tri_embeds at the bottom.

User avatar
aaronstj
Posts: 66
Joined: Wed Jul 06, 2005 11:34 am
Location: Seattle

Post by aaronstj »

Intersting. Another fun thing to do is reduce the size of the white circle, say to .75 or .5.

Post Reply