@ストローク用アンカー
--track0:ｱﾝｶｰ数,1,12,3,1
--dialog:追加座標,anc={-100,0,0,0,100,0};
--追加削除対策で#は使わない
	local k=obj.track0
	obj.setanchor("anc",k,"line")
	if T_strokeTM_ancB==nil then
		T_strokeTM_ancB={}
		T_strokeTM_N=0
	end
	for i=1,2*k do
		T_strokeTM_ancB[2*T_strokeTM_N+i]=anc[i]
	end
	T_strokeTM_N=T_strokeTM_N+k

	if obj.getoption("script_name",1,true):sub(-4,-1)~=obj.getoption("script_name"):sub(-4,-1) then
		T_stroke_f()
		T_strokeTM_ancB=nil
		T_strokeTM_N=nil
	end


@ストローク(反復)
--track0:進捗度,0,100,50,0.01
--track1:左端残し,0,2000,0,1
--track2:右端残し,0,2000,0,1
--track3:繰返ﾓｰﾄﾞ,1,3,1,1
--dialog:軌道精度,local smN=30;環状軌道/chk,local CirObt=0;軌道[0-1],local richk=1;先頭調整/chk,local topadj=0;幅変動[%],local fat={100,100,100};z軸方向,local posZ={0,0,0};最大ﾗﾝﾀﾞﾑ長[%],local RnD=50;乱数シード,local seed=0;ﾌﾚｰﾑﾊﾞｯﾌｧ表示/chk,local fbapp=0;

local sp1=obj.track1
local sp2=obj.track2
local t=obj.track0*0.01
local AP=obj.track3  --1は根本固定、2は先端固定、3はランダム
topadj=topadj or 2 --互換用

T_stroke_f=function()

	local interpolationT
	if richk==0 then
		interpolationT=function(t,x0,y0,x1,y1,x2,y2,x3,y3)
			if t<=0.5 then
				s=t+0.5
				return ( (1-s)*(1-s)*x0+(1+2*s-2*s*s)*x1+s*s*x2 )/2 , ( (1-s)*(1-s)*y0+(1+2*s-2*s*s)*y1+s*s*y2 )/2
			else
				s=t-0.5
				return ( (1-s)*(1-s)*x1+(1+2*s-2*s*s)*x2+s*s*x3 )/2 , ( (1-s)*(1-s)*y1+(1+2*s-2*s*s)*y2+s*s*y3 )/2
			end
		end
	elseif richk==1 then
		interpolationT=function(t,x0,y0,x1,y1,x2,y2,x3,y3)--正方形配置で円になるように特殊な計算
			local s,Ax,Ay,Cx,Cy,Dx,Dy,Ex,Ey,Fx,Fy
			if t<=0.5 then
				t=t+0.5
				Ex,Ey=(x0+x1)*0.5 , (y0+y1)*0.5
				Dx,Dy=x1,y1
				Fx,Fy=(x1+x2)*0.5 , (y1+y2)*0.5
			else
				t=t-0.5
				Ex,Ey=(x1+x2)*0.5 , (y1+y2)*0.5
				Dx,Dy=x2,y2
				Fx,Fy=(x2+x3)*0.5 , (y2+y3)*0.5
			end
			t=math.tan(math.pi*0.5*t*0.5)
			Ax,Ay=(1-t)*Ex+t*Dx , (1-t)*Ey+t*Dy
			s=2*t/(1+t)
			Cx,Cy=(1-s)*Dx+s*Fx , (1-s)*Dy+s*Fy
			s=t*(1+t)/(1+t*t)
			return (1-s)*Ax+s*Cx , (1-s)*Ay+s*Cy
		end

	else
		interpolationT=function(t,x0,y0,x1,y1,x2,y2,x3,y3)
			return (1-t)*x1+t*x2 , (1-t)*y1+t*y2
		end

	end

	local DistanceCor=function(PX,PY,N)
		local Long={}
		local iPX={}
		local iPY={}
		iPX[0],iPY[0]=PX[0],PY[0]
		iPX[N],iPY[N]=PX[N],PY[N]
		Long[0]=0
		for i=1,N do
			Long[i]=Long[i-1]+math.sqrt((PX[i]-PX[i-1])^2+(PY[i]-PY[i-1])^2)
		end
		local CON=Long[N]/N
		local M=1
		for i=1,N-1 do
			local  DIS=i*CON
			while DIS>Long[M] do
				M=M+1
			end
			local rate=(DIS-Long[M-1])/(Long[M]-Long[M-1])
			iPX[i]=PX[M-1]+rate*(PX[M]-PX[M-1])
			iPY[i]=PY[M-1]+rate*(PY[M]-PY[M-1])
		end
		return iPX,iPY,math.floor(Long[N])
	end

	local CalArray=function(t,Arr)--倍率用
		local N=#Arr
		if N==1 then
			return Arr[1]
		end
		local s=1+t*(N-1)
		local Q1=math.floor(s)
		local Q0=math.max(1,Q1-1)
		local Q2=math.min(N,Q1+1)
		local Q3=math.min(N,Q1+2)
		s=s-Q1
		return obj.interpolation(s,Arr[Q0],Arr[Q1],Arr[Q2],Arr[Q3])
	end

	local CalArray2=function(t,Arr)--Z座標用
		local N=#Arr
		if N==1 then
			return Arr[1]
		end
		local s=1+t*(N-1)
		local Q1=math.floor(s)
		local Q0=Q1-1
		local Q2=Q1+1
		local Q3=Q1+2
		s=s-Q1
		if Q0<1 then Q0=2*Arr[1]-Arr[2] else Q0=Arr[Q0] end
		Q1=Arr[Q1]
		if Q2>N then Q2=2*Arr[N]-Arr[N-1] else Q2=Arr[Q2] end
		if Q3>N+1 then
			Q3=3*Arr[N]-2*Arr[N-1]
		elseif Q3>N then
			Q3=2*Arr[N]-Arr[N-1]
		else
			Q3=Arr[Q3]
		end
		return obj.interpolation(s,Q0,Q1,Q2,Q3)
	end

	local RVEC=function(x1,x2,y1,y2,h)
		local	dx=x1-x2
		local	dy=y1-y2
		local	dr=math.sqrt(dx*dx+dy*dy)
		return 0.5*dx*h/dr , 0.5*dy*h/dr
	end

	local acN=T_strokeTM_N
	local anc=T_strokeTM_ancB

	if CirObt==1 then
		acN=acN+1
		anc[2*acN-1],anc[2*acN]=anc[1],anc[2]
	end

	local w0,h0=obj.getpixel()--オリジナルサイズ
	RnD=math.min(1,math.max(0.05,RnD*0.01))
	smN=math.min(1000,math.max(1,math.floor(smN)))
	sp1=math.floor(math.min(sp1,w0-2))
	sp2=math.floor(math.min(sp2,w0-sp1-1))
	obj.copybuffer("cache:ori","obj")--オリジナルを保存

	obj.effect("クリッピング","左",sp1,"右",sp2)--両端をカット
	local w,h=w0-(sp1+sp2),h0 --両端カットサイズ
	obj.copybuffer("cache:moyou","obj")--両端カットを保存

	for i=1,#fat do
		fat[i]=fat[i]*0.01
	end

--座標データ作成

	local ancX={}
	local ancY={}

	for i=1,acN do
		ancX[i]=anc[2*i-1]
		ancY[i]=anc[2*i]
	end

	if CirObt==1 then
		ancX[0]=ancX[acN-1]
		ancY[0]=ancY[acN-1]
		ancX[acN+1]=ancX[2]
		ancY[acN+1]=ancY[2]
	else
		ancX[0]=2*ancX[1]-ancX[2]
		ancY[0]=2*ancY[1]-ancY[2]
		ancX[acN+1]=2*ancX[acN]-ancX[acN-1]
		ancY[acN+1]=2*ancY[acN]-ancY[acN-1]
	end

--距離、座標設定
	local posX={}
	local posY={}
	local Long={}
	for i=1,acN-1 do
		posX[i]={}
		posY[i]={}
		for k=0,smN do
			posX[i][k],posY[i][k]=interpolationT(k/smN,ancX[i-1],ancY[i-1], ancX[i],ancY[i], ancX[i+1],ancY[i+1], ancX[i+2],ancY[i+2])
		end
		posX[i],posY[i],Long[i]=DistanceCor(posX[i],posY[i],smN)
	end

--距離再計算
	local LongS={}
	LongS[0]=0
	for i=1,acN-1 do
		LongS[i]=LongS[i-1]+Long[i]
	end
	local AllLong=LongS[acN-1]


--輪郭計算用
	for i=2,acN-1 do
		posX[i][-1]=posX[i-1][smN-1]
		posY[i][-1]=posY[i-1][smN-1]
	end
	for i=1,acN-2 do
		posX[i][smN+1]=posX[i+1][1]
		posY[i][smN+1]=posY[i+1][1]
	end
	if CirObt==1 then
		posX[1][-1]=posX[acN-1][smN-1]
		posY[1][-1]=posY[acN-1][smN-1]
		posX[acN-1][smN+1]=posX[1][1]
		posY[acN-1][smN+1]=posY[1][1]
	else
		posX[1][-1]=2*posX[1][0]-posX[1][1]
		posY[1][-1]=2*posY[1][0]-posY[1][1]
		posX[acN-1][smN+1]=2*posX[acN-1][smN]-posX[acN-1][smN-1]
		posY[acN-1][smN+1]=2*posY[acN-1][smN]-posY[acN-1][smN-1]
	end


--幅調整
	local HH={}
	for i=1,acN-1 do
		HH[i]={}
		for k=0,smN do
			local t=(k*Long[i]/smN+LongS[i-1])/AllLong
			HH[i][k]=h*CalArray(t,fat)
		end
	end


--輪郭作成
	local posTX={}
	local posTY={}
	local posBX={}
	local posBY={}
	for i=1,acN-1 do
		posTX[i]={}
		posTY[i]={}
		posBX[i]={}
		posBY[i]={}
		for k=0,smN do
			local dx,dy=RVEC(posX[i][k-1],posX[i][k+1],posY[i][k-1],posY[i][k+1],HH[i][k])
			posTX[i][k]=posX[i][k]+dy
			posTY[i][k]=posY[i][k]-dx
			posBX[i][k]=posX[i][k]-dy
			posBY[i][k]=posY[i][k]+dx
		end
	end


--ブロック最大値を計算
	local acmax=1
	local acmaxb=1
	if t<1 then
		while LongS[acmaxb]<t*(AllLong-sp1-sp2)+sp1 do
			acmaxb=acmaxb+1
		end
		acmax=acmaxb
		while LongS[acmax]<t*(AllLong-sp1-sp2)+sp1+sp2 do
			acmax=acmax+1
		end

	else
		acmax=acN-1
		acmaxb=acmax
	end

--ブロック単位で画像作成
	local xlong=t*(AllLong-sp1-sp2)
	local sft=0

	if AP<3 then
		if AP==1 then
			sft=sp1-w
		else
			sft=(sp1+xlong)%w-w
		end

		for i=1,acmax do
			obj.setoption("drawtarget","tempbuffer",Long[i],h)
			obj.setoption("blend","alpha_add2")
			local nw=math.floor((Long[i]-sft)/w)+1
			local longh=Long[i]*0.5

			if AP==1 or (AP==2 and i~=acmax and (i~=acmaxb or acmax==acmaxb))then
				for j=0,nw do
					obj.draw(-longh+sft+w*(j+0.5))
				end
			elseif (i==acmax and acmax==acmaxb) or (i==acmaxb and acmax~=acmaxb) then
					for j=0,nw do
						obj.draw(-longh+xlong+sp1-LongS[i-1]-w*(j+0.5))
					end
			end

			sft=-((Long[i]-sft)%w)
			obj.copybuffer("cache:line"..i,"tmp")
		end
	else

		local y1=h*0.5
		local y0=-y1
		local RnDw=RnD*w

		local a={}
		a[-2]=0
		a[-1]=w
		a[0]=0
		local dL=-2*w+sp1
		local RL=sp1
		for i=1,acmax do
			obj.setoption("drawtarget","tempbuffer",Long[i],h)
			obj.setoption("blend","alpha_add2")
			local n=0

			repeat
				a[n+1]=obj.rand(a[n],a[n]+RnDw,i,n+1000+seed)
				n=n+1
				if a[n]>w then a[n]=w end
				a[n+1]=obj.rand(a[n]-RnDw,a[n],i,n+1000+seed)
				n=n+1
				if a[n]<0 then a[n]=0 end
				RL=RL+(2*a[n-1]-a[n-2]-a[n])
			until (RL>=Long[i])

			local sht=-Long[i]*0.5+dL
			for i=0,n,2 do
				local u0,u1,x0,x1,du

				u0=a[i-2]
				u1=a[i-1]
				du=u1-u0
				x0=sht
				x1=sht+du
				obj.drawpoly(x0,y0,0, x1,y0,0, x1,y1,0, x0,y1,0,  u0,0,u1,0,u1,h,u0,h)
				sht=sht+du

				u0=a[i]
				u1=a[i-1]
				du=u1-u0
				x0=sht+du
				x1=sht
				obj.drawpoly(x0,y0,0, x1,y0,0, x1,y1,0, x0,y1,0,  u0,0,u1,0,u1,h,u0,h)
				sht=sht+du
			end
			obj.copybuffer("cache:line"..i,"tmp")

			a[-2]=a[n-2]
			a[-1]=a[n-1]
			a[ 0]=a[n  ]
			RL=RL-Long[i]
			dL=RL-(2*a[n-1]-a[n-2]-a[n])
		end

	end

	obj.copybuffer("obj","cache:line1")
	obj.effect("クリッピング","左",sp1)
	obj.effect("領域拡張","左",sp1)
	obj.copybuffer("tmp","obj")
	obj.copybuffer("obj","cache:ori")
	obj.effect("クリッピング","右",w+sp2)
	obj.draw((-Long[1]+sp1)*0.5,0)			
	obj.copybuffer("cache:line1","tmp")

	for i=acmaxb,acmax do
		local X=xlong+sp1-LongS[i-1]-Long[i]*0.5
		obj.copybuffer("obj","cache:line"..i)
		obj.effect("斜めクリッピング","角度",-90,"中心X",X,"ぼかし",0)
		obj.copybuffer("tmp","obj")
		obj.copybuffer("obj","cache:ori")
		obj.effect("クリッピング","左",w+sp1)
		obj.draw(X+sp2*0.5-topadj*0.5,0)
		obj.copybuffer("cache:line"..i,"tmp")	
	end


	if fbapp==0 then
--最大最小検出
		local maxX=posTX[1][0]
		local minX=posTX[1][0]
		local maxY=posTY[1][0]
		local minY=posTY[1][0]
		for i=1,acmax do
			for k=0,smN do
				maxX=math.max(posTX[i][k],posBX[i][k],maxX)
				minX=math.min(posTX[i][k],posBX[i][k],minX)
				maxY=math.max(posTY[i][k],posBY[i][k],maxY)
				minY=math.min(posTY[i][k],posBY[i][k],minY)
			end
		end
	
		local ww=maxX-minX
		local hh=maxY-minY
		local cw=(maxX+minX)*0.5
		local ch=(maxY+minY)*0.5
	
		obj.setoption("drawtarget","tempbuffer",ww,hh)
		obj.setoption("blend","alpha_add2")
		for i=1,acmax do
			obj.copybuffer("obj","cache:line"..i)
			for k=0,smN-1 do
				local x0,y0=posTX[i][k  ]-cw,posTY[i][k  ]-ch
				local x1,y1=posTX[i][k+1]-cw,posTY[i][k+1]-ch
				local x2,y2=posBX[i][k+1]-cw,posBY[i][k+1]-ch
				local x3,y3=posBX[i][k  ]-cw,posBY[i][k  ]-ch
				local u0=Long[i]*k/smN
				local u1=Long[i]*(k+1)/smN
				obj.drawpoly(x0,y0,0,x1,y1,0,x2,y2,0,x3,y3,0, u0,0,u1,0,u1,h,u0,h)
			end
		end
		obj.load("tempbuffer")
		obj.setoption("blend",0)
		obj.cx=-cw
		obj.cy=-ch
	else
		local zz={}
		for i=1,acmax do
			zz[i]={}
			for k=0,smN do
				local t=(k*Long[i]/smN+LongS[i-1])/AllLong
				zz[i][k]=CalArray2(t,posZ)
			end
		end
		obj.setoption("drawtarget","framebuffer")
		for i=1,acmax do
			obj.copybuffer("obj","cache:line"..i)
			obj.cx=0
			obj.cy=0
			for k=0,smN-1 do
				local x0,y0=posTX[i][k  ],posTY[i][k  ]
				local x1,y1=posTX[i][k+1],posTY[i][k+1]
				local x2,y2=posBX[i][k+1],posBY[i][k+1]
				local x3,y3=posBX[i][k  ],posBY[i][k  ]
				local u0=Long[i]*k/smN
				local u1=Long[i]*(k+1)/smN
				obj.drawpoly(x1,y1,zz[i][k+1],x0,y0,zz[i][k],x3,y3,zz[i][k],x2,y2,zz[i][k+1], u1,0,u0,0,u0,h,u1,h)
			end
		end
		obj.setoption("blend",0)
	end
end

	if obj.getoption("script_name",1,true):sub(-4,-1)~=obj.getoption("script_name"):sub(-4,-1) then
		T_stroke_f()
		T_strokeTM_ancB=nil
		T_strokeTM_N=nil
	end


@ストローク(配置:変動)
--track0:誤差X,0,10000,100
--track1:誤差Y,0,10000,100
--track2:誤差ｻｲｽﾞ,0,1000,80
--track3:誤差角度,0,3600,180
--dialog:誤差透明度,local GosaA=50;乱数シード,local seed=0;拡大率変動[%],local zoomt={100,100,100};角度変動,local rott={0,0,0};透明度変動[%],local alpt={0,0,0};
	
	T_strokeTM_GosaX=obj.track0
	T_strokeTM_GosaY=obj.track1
	T_strokeTM_GosaS=obj.track2
	T_strokeTM_GosaR=obj.track3
	T_strokeTM_GosaA=GosaA
	T_strokeTM_seed=seed
	T_strokeTM_zoomt=zoomt
	T_strokeTM_rott=rott
	T_strokeTM_alpt=alpt
	T_strokeTM_rnd=1

	if obj.getoption("script_name",1,true):sub(-4,-1)~=obj.getoption("script_name"):sub(-4,-1) then
		T_stroke_f()
		T_strokeTM_ancB=nil
		T_strokeTM_N=nil
	end


@ストローク(配置)
--track0:進捗度1,0,100,100,0.01
--track1:進捗度2,0,100,0,0.01
--track2:区間個数,1,5000,10,1
--track3:ﾗﾝﾀﾞﾑ性,0,100,0
--dialog:重なり反転/chk,local apchk=0;環状軌道/chk,local CirObt=0;軌道[0_2],local richk=1;進行方向/chk,local vecchk=0;先頭表示/chk,local topOnly=0;位置ランダム性,local Gosa=200;領域拡大,local dScr=0;精度,local smN=20;

local t1=obj.track0*0.01
local t2=obj.track1*0.01
if t2<t1 then t1,t2=t2,t1 end
local posN=obj.track2
local rnd=obj.track3*0.01

T_stroke_f=function()
	local t_To_D=function(Datat,posN)
		local DataD={}
		local fN=#Datat
		Datat[0]=Datat[1]
		Datat[fN+1]=Datat[fN]
		Datat[fN+2]=Datat[fN]
		for i=0,posN do
			local x=i*(fN-1)/posN+1
			local xn=math.floor(x)
			local dx=x-xn
			DataD[i]=obj.interpolation(dx,Datat[xn-1],Datat[xn],Datat[xn+1],Datat[xn+2])
		end
		return DataD
	end

	local interpolationT=(function(k)
		if k==0 then
			return function(t,x0,y0,x1,y1,x2,y2,x3,y3)
				if t<=0.5 then
					s=t+0.5
					return ( (1-s)*(1-s)*x0+(1+2*s-2*s*s)*x1+s*s*x2 )/2 , ( (1-s)*(1-s)*y0+(1+2*s-2*s*s)*y1+s*s*y2 )/2
				else
					s=t-0.5
					return ( (1-s)*(1-s)*x1+(1+2*s-2*s*s)*x2+s*s*x3 )/2 , ( (1-s)*(1-s)*y1+(1+2*s-2*s*s)*y2+s*s*y3 )/2
				end
			end
		elseif k==1 then
			return function(t,x0,y0,x1,y1,x2,y2,x3,y3)--正方形配置で円になるように特殊な計算
				local s,Ax,Ay,Cx,Cy,Dx,Dy,Ex,Ey,Fx,Fy
				if t<=0.5 then
					t=t+0.5
					Ex,Ey=(x0+x1)*0.5 , (y0+y1)*0.5
					Dx,Dy=x1,y1
					Fx,Fy=(x1+x2)*0.5 , (y1+y2)*0.5
				else
					t=t-0.5
					Ex,Ey=(x1+x2)*0.5 , (y1+y2)*0.5
					Dx,Dy=x2,y2
					Fx,Fy=(x2+x3)*0.5 , (y2+y3)*0.5
				end
				t=math.tan(math.pi*0.5*t*0.5)
				Ax,Ay=(1-t)*Ex+t*Dx , (1-t)*Ey+t*Dy
				s=2*t/(1+t)
				Cx,Cy=(1-s)*Dx+s*Fx , (1-s)*Dy+s*Fy
				s=t*(1+t)/(1+t*t)
				return (1-s)*Ax+s*Cx , (1-s)*Ay+s*Cy
			end
		else
			return function(t,x0,y0,x1,y1,x2,y2,x3,y3)
				return (1-t)*x1+t*x2 , (1-t)*y1+t*y2
			end
		end
	end)(richk)


	local GosaX,GosaY,GosaS,GosaR,GosaA,seed
	local zoomt,rott,alpt

	if T_strokeTM_rnd then
		GosaX=T_strokeTM_GosaX
		GosaY=T_strokeTM_GosaY
		GosaS=T_strokeTM_GosaS
		GosaR=T_strokeTM_GosaR
		GosaA=T_strokeTM_GosaA
		seed=T_strokeTM_seed
		zoomt=T_strokeTM_zoomt
		rott=T_strokeTM_rott
		alpt=T_strokeTM_alpt
	else
		GosaX=Gosa
		GosaY=Gosa
		GosaS=60
		GosaR=40
		GosaA=0
		seed=0
		zoomt={100}
		rott={0}
		alpt={0}
	end
	T_strokeTM_rnd=nil

	local anc=T_strokeTM_ancB
	local acN=T_strokeTM_N

	if CirObt==1 then
		acN=acN+1
		anc[2*acN-1]=anc[1]
		anc[2*acN]=anc[2]
	end

	local ancX={}
	local ancY={}
	for i=1,acN do
		ancX[i]=anc[2*i-1]
		ancY[i]=anc[2*i]
	end

	if CirObt==0 then
		ancX[0]=2*ancX[1]-ancX[2]
		ancY[0]=2*ancY[1]-ancY[2]
		ancX[acN+1]=2*ancX[acN]-ancX[acN-1]
		ancY[acN+1]=2*ancY[acN]-ancY[acN-1]
	else
		ancX[0]=ancX[acN-1]
		ancY[0]=ancY[acN-1]
		ancX[acN+1]=ancX[2]
		ancY[acN+1]=ancY[2]
	end

	local iposX={}
	local iposY={}
	local inum=1
	local x0,y0=ancX[0],ancY[0]
	local x1,y1=ancX[1],ancY[1]
	local x2,y2=ancX[2],ancY[2]
	for i=1,acN-1 do
		local x3,y3=ancX[i+2],ancY[i+2]
		for j=0,smN-1 do
			local time=j/smN
			iposX[inum],iposY[inum] =interpolationT(time,x0,y0,x1,y1,x2,y2,x3,y3)
			inum=inum+1
		end
		x0,y0=x1,y1
		x1,y1=x2,y2
		x2,y2=x3,y3
	end
	if CirObt==0 then
		iposX[inum],iposY[inum]=ancX[acN],ancY[acN]
	else
		iposX[inum],iposY[inum]=iposX[1],iposY[1]
	end
	local ALL={}
	ALL[0]=0
	for i=1,inum-1 do
		ALL[i]=ALL[i-1]+math.sqrt((iposX[i+1]-iposX[i])^2+(iposY[i+1]-iposY[i])^2)
	end
--posN
	local posX={}
	local posY={}

	local step=ALL[inum-1]/(posN-1)



	local k=1
	local i=1
	posX[1],posY[1]=iposX[1],iposY[1]

	repeat
		if ALL[i]>k*step then
			local y=(k*step-ALL[i-1])/(ALL[i]-ALL[i-1])
			k=k+1
			posX[k]=(1-y)*iposX[i]+y*iposX[i+1]
			posY[k]=(1-y)*iposY[i]+y*iposY[i+1]
		else
			i=i+1
		end
	until i>inum-1

	if CirObt==0 then
		posX[posN],posY[posN]=iposX[inum],iposY[inum]
		posX[0],posY[0]=posX[1],posY[1]
		posX[posN+1],posY[posN+1]=posX[posN],posY[posN]
	else
		posX[posN],posY[posN]=posX[1],posY[1]
		posX[0],posY[0]=posX[posN-1],posY[posN-1]
		posX[posN+1],posY[posN+1]=posX[2],posY[2]
		posN=posN-1
	end
	local i1,i2,sti
	if apchk==0 then
		i1=math.floor(1+(posN-1)*t1)
		i2=math.floor(1+(posN-1)*t2)
		sti=1
	else
		i2=math.floor(1+(posN-1)*t1)
		i1=math.floor(1+(posN-1)*t2)
		sti=-1
	end
	if topOnly==1 then i1=math.ceil(i2) end

	--変動率率作成
	local xD={}
	local yD={}
	local zoomD={}
	local rotD={}
	local alpD={}

	zoomD=t_To_D(zoomt, posN)
	rotD =t_To_D(rott , posN)
	alpD =t_To_D(alpt , posN)

	--自動角度
	dR={}
	if vecchk==1 then
		for i=1,posN do
			dR[i]=math.deg(math.atan2(posY[i+1]-posY[i-1],posX[i+1]-posX[i-1]))
		end
	else
		for i=1,posN do
			dR[i]=0
		end
	end

	for i=1,posN do
		posX[i]=posX[i]+obj.rand(-GosaX*0.5,GosaX*0.5,i,1000+seed)*rnd
		posY[i]=posY[i]+obj.rand(-GosaY*0.5,GosaY*0.5,i,2000+seed)*rnd
	end

	--最大最小検出
	local maxX=posX[1]
	local minX=posX[1]
	local maxY=posY[1]
	local minY=posY[1]
	for i=2,posN do
		maxX=math.max(posX[i],maxX)
		minX=math.min(posX[i],minX)
		maxY=math.max(posY[i],maxY)
		minY=math.min(posY[i],minY)
	end

	local w,h=obj.getpixel()
	local dw=math.max(w,h)

	local ww=maxX-minX+dw+dScr
	local hh=maxY-minY+dw+dScr
	local cw=(maxX+minX)*0.5
	local ch=(maxY+minY)*0.5

	obj.setoption("drawtarget","tempbuffer",ww,hh)

	for i=i1,i2,sti do
		local zoom=zoomD[i]*(1+obj.rand(-GosaS*0.5,GosaS*0.5,i,3000+seed)*rnd*0.01)*0.01
		local alpha=(100-alpD[i])*(1+obj.rand(-GosaA*0.5,GosaA*0.5,i,4000+seed)*rnd*0.01)
		local rz=obj.rand(-GosaR*0.5,GosaR*0.5,i,5000+seed)*rnd+dR[i]+rotD[i]
		alpha=math.min(1,math.max(0,alpha*0.01))
		obj.draw(posX[i]-cw,posY[i]-ch,0,zoom,alpha,0,0,rz)
	end

	obj.load("tempbuffer")
	obj.cx=obj.cx-cw
	obj.cy=obj.cy-ch
end

	if obj.getoption("script_name",1,true):sub(-4,-1)~=obj.getoption("script_name"):sub(-4,-1) then
		T_stroke_f()
		T_strokeTM_ancB=nil
		T_strokeTM_N=nil
	end
