double helix ?

If you're having trouble using Context Free or don't understand the language, ask for help here.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
hmny
Posts: 6
Joined: Sun Mar 15, 2009 3:21 pm

double helix ?

Post by hmny »

Hi! This is truely a great program :)

I'm amazed what people can create using simple formulas!

Trying to create a double helix shape.....

Code: Select all

startshape HELIX

path rond {
	MOVETO { x 0.5  y 0.5 }
	ARCREL { x 0.75  y 0.75 }
	ARCREL { x 0.75 y 0.5 }
	STROKE { width 0.01 }
}

rule HELIXHALF {
	rond {}
	rond{  flip 45 } 
}

rule HELIX {
	HELIXHALF { x -1   }
	HELIXHALF { y 1 r 180 }
}
That works. I was wondering if I can make that helix now into a circle shape somehow ?? Also maybe someone knows a much smarter way todo this.

Thanks

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

Post by MtnViewJohn »

This code is a pretty good approximation.

Code: Select all

startshape DNAring

rule DNAring {
	ring{}
	ring{r 2.5}
}

path ring {
	MOVETO {x 1}
	36* {r (360/36)} {
		CURVETO {
			x cos(180/36) y sin(180/36)
			x1 (sqrt(2) * cos(90/36)) 
			y1 (sqrt(2) * sin(90/36))
		}
		CURVETO {
			x cos(360/36) y sin(360/36)
			x1 (sqrt(0.5) * cos(270/36)) 
			y1 (sqrt(0.5) * sin(270/36))
		}
	}
	CLOSEPOLY{p align}
	STROKE {width 0.01}
}
But there are slight curvature discontinuities. Using cubic bezier curves can fix these:

Code: Select all

path ring {
	MOVETO {x 1.25}
	36 * {r (360/36)} {
		CURVETO {
			x cos(180/36) y sin(180/36) 
			x1 1.25 y1 0.05 
			x2 (cos(180/36) + 0.05 * sin(180/36)) 
			y2 (sin(180/36) - 0.05 * cos(180/36))
		}
		CURVETO {
			x (1.25 *cos(360/36)) y (1.25 * sin(360/36)) 
			x2 (1.25 * cos(360/36) + 0.05 * sin(360/36)) 
			y2 (1.25 * sin(360/36) - 0.05 * cos(360/36))
		}
	}
	CLOSEPOLY {p align}
	STROKE {width 0.01}
}

hmny
Posts: 6
Joined: Sun Mar 15, 2009 3:21 pm

Post by hmny »

hey this looks good! thanks alot. I'll play with this code and learn :)

Post Reply