@PolygonArrangement-1(Definition)
--track0:Loop,0,100,1
--track1:Gap,-1000,1000,0
--track2:Twist,-360,360,0
--track3:Facing,0,2,1
--param:kijun=0;
sz_rep=math.floor(obj.track0)
sz_space=obj.track1
sz_rot=obj.track2
sz_dir=math.floor(obj.track3)
shiftX=0
shiftY=0
shiftZ=0
shiftR=0


@Polygon drift settings
--track0:dx,-1000,1000,0
--track1:dy,-1000,1000,0
--track2:dz,-1000,1000,0
--track3:dRadius,-1000,1000,0

shiftX=obj.track0
shiftY=obj.track1
shiftZ=obj.track2
shiftR=obj.track3


@PolygonArrangement-2(Render)
--track0:N-gon,3,30,5
--track1:Count,0,30,5
--track2:RadiusAdj,-1000,1000,0
--track3:Spin,-3600,3600,0
--check0:Lineup vertically,0

n=math.floor(obj.track0)
disp=math.floor(obj.track1)
if ( n < disp ) then
  disp=n
end
radjust=obj.track2
rotadjust=obj.track3
dir=obj.check0
theta=math.pi*(n-2)/(2*n)
if ( dir ) then
    basesize=obj.h
    shiftObj=obj.w
    if(kijun==1) then
      
      baseX = -0.5*(sz_rep-1)*(obj.w+sz_space+shiftX)
      baseY = -0.5*(sz_rep-1)*shiftY
      baseZ = -0.5*(sz_rep-1)*shiftZ
      baseSpin = -0.5*(sz_rep-1)*sz_rot
      baseR = (basesize*math.tan(theta)/2+radjust) - 0.5*(sz_rep-1)*shiftR
    else
      
      baseX = 0
      baseY = 0
      baseZ = 0
      baseSpin = 0
      baseR = (basesize*math.tan(theta)/2+radjust)
    end
else
    basesize=obj.w
    shiftObj=obj.h
    if(kijun==1) then
      
      baseX = -0.5*(sz_rep-1)*shiftX
      baseY = -0.5*(sz_rep-1)*(obj.h+sz_space+shiftY)
      baseZ = -0.5*(sz_rep-1)*shiftZ
      baseSpin = -0.5*(sz_rep-1)*sz_rot
      baseR = (basesize*math.tan(theta)/2+radjust) - 0.5*(sz_rep-1)*shiftR
    else
      
      baseX = 0
      baseY = 0
      baseZ = 0
      baseSpin = 0
      baseR = (basesize*math.tan(theta)/2+radjust)
    end
end
if(kijun==2) then
  sz_space=-sz_space
  sz_rot = -sz_rot
  shiftX = -shiftX
  shiftY = -shiftY
  shiftZ = -shiftZ
  shiftR = -shiftR
  shiftObj = -shiftObj
end
for j=0,sz_rep-1 do
  r = baseR + shiftR * j
  rotshift = baseSpin + sz_rot*j
  if(dir) then
      diffX = baseX + (shiftObj + sz_space + shiftX) * j
      diffY = baseY + shiftY * j
      diffZ = baseZ + shiftZ * j
  else
      diffX = baseX + shiftX * j
      diffY = baseY + (shiftObj + sz_space + shiftY) * j
      diffZ = baseZ + shiftZ * j
  end
  for i=0,disp-1 do
    rot = i*360/n+rotadjust+rotshift
    if ( dir ) then
      y = r*math.sin(math.pi/180*rot)
      z = -r*math.cos(math.pi/180*rot)
      if(sz_dir==0) then
        rot = 0
      elseif(sz_dir==2) then
        rot = rot + 180
      end
      obj.draw(diffX,y+diffY,z+diffZ,1,1,rot,0,0)
    else
      x = -r*math.sin(math.pi/180*rot)
      z = -r*math.cos(math.pi/180*rot)
      if(sz_dir==0) then
        rot = 0
      elseif(sz_dir==2) then
        rot = rot + 180
      end
      obj.draw(x+diffX,diffY,z+diffZ,1,1,0,rot,0)
    end
  end
end