gear=tube()
w=20.
gear.height=w 
gear.sides=5
kz=15
mdl=5. as float 
rout=kz*mdl/2+mdl as float
rosn=kz*mdl/2*cos(20)
gear.radius1=rout
gear.radius2=kz*mdl/2-3*mdl
np=10
gear.sides=kz*np
da=360./kz/np as float
ag=0. as float 
convertToMesh gear
k=0
for j=1 to j=kz do(
  for i=1 to i=np do (
    r=rout-mdl-1.8*mdl*sin((i as float)/np*360.)
	if r > rout then
      r=rout
	else
      if r < rout-2.25*mdl then
        r=rout-2.25*mdl
	  else(
	    r=rosn
      )	
  	x=r*sin(ag+da*i)
	y=r*cos(ag+da*i)
	setVert gear (1+k*4) x y 0
	setVert gear (2+k*4) x y w
	k=k+1
  )
  ag=ag+np*da
)
update gear