@Firework Setting
--track0:CenterX,-1000,1000,0
--track1:CenterY,-1000,1000,0
--track2:Zoom%,0,400,100
--color:0xFFFF80

centerx = obj.track0
centery = obj.track1
zoom = obj.track2
ptcolor = color

@Firework
--track0:DivSize,2,20,4
--track1:Pt.Size,1,20,4
--track2:Threshold,-100,100,40
--track3:Pt.drift,0,50,5
--dialog:Coordinate,pos={0,0,0,0};

-- nil対策
if centerx == nil then	centerx = 0 end
if centery == nil then	centery = 0 end
if zoom == nil then zoom = 100 end
if ptcolor == nil then ptcolor = 0xFFFF80 end

local	zoomsize = zoom/100
local	divsize = math.floor(obj.track0)
local	ptsize = math.floor(obj.track1)
local	threshold = obj.track2
local	shake = math.floor(obj.track3)

-- 数値入力中に固まったように重くなるので一応リミッタ
if (divsize < 2) then divsize = 2 end

-- 画像から表示するべき点リストを作成する
function createpoints(ofx,ofy)
	pt = {}
	local	ct = 0
	local	cs = divsize
	local	xs = obj.w / cs
	local	ys = obj.h / cs

	math.randomseed (obj.totaltime+pos[1]+pos[2])

	for y = 0, ys-1 do
		for x = 0, xs-1 do
			col = 0
			pixy,pixcb,pixcr,pixa = obj.getpixel (x*cs+divsize/2, y*cs+divsize/2, "yc")
			if (pixa > 100) then
				xp = (x*cs-obj.w/2-ofx/zoomsize+divsize/2) * zoomsize
				yp = (y*cs-obj.h/2-ofy/zoomsize+divsize/2) * zoomsize
				t = { x = xp+math.random()*shake-shake/2, y = yp+math.random()*shake-shake/2 }
				pt[ct] = t;
				ct = ct + 1
			end
		end
	end

	return	pt
end

-- ３次ベジェ曲線
-- 中間点を重ねてそれっぽくなるように
function bezier (cx, cy, x, y, t)
	local	t0 = math.pow (1-t, 3)
	local	t1 = math.pow (1-t, 2)
	local	t2 = math.pow (t, 2)
	local	t3 = math.pow (t, 3)

	local	xp = cx * t0 + x * t * 3 * t1 + x * 3 * (1-t) * t2 + x * t3
	local	yp = cy * t0 + y * t * 3 * t1 + y * 3 * (1-t) * t2 + (y+50) * t3

	return	xp, yp
end

obj.setanchor("pos",1)

local	xo = centerx
local	yo = centery
local	xc = pos[1]
local	yc = pos[2]

obj.effect ("Edge extraction", "Strength", 100, "Threshold", threshold)
obj.effect ("Mosaic", "Size", divsize)

points = createpoints(xo, yo)

obj.setoption("drawtarget", "tempbuffer", obj.screen_w, obj.screen_h)

local	t = obj.time / obj.totaltime
local	xo = obj.screen_w/2
local	yo = obj.screen_h/2

obj.load ("figure", "Pentagon", ptcolor, ptsize)
math.randomseed(obj.frame)
for p = 1, table.maxn(points) do
		-- 位置計算
		x = points[p].x
		y = points[p].y
		xp, yp = bezier (0, 0, x, y, t)

		-- 点滅
		local	a = 1.0-math.random()*0.5

		-- 最初は暗く
		if (t < 0.2) then
			a = a * t * 5
		end

		-- 一定以上で消えていく
		if (t > 0.7) then
			a = a - (t-0.7)*3
			if (a < 0) then
				a = 0
			end
		end

		-- なんかそれっぽく尻尾つける
		t2 = t-0.05
		if (t2 < 0) then
			t2 = 0
		end
		xp2, yp2 = bezier (0, 0, x, y, t2)

		dx = xp - xp2
		dy = yp - yp2
		d = math.sqrt(dx*dx + dy*dy)*zoomsize
		if (d > 20) then
			d = 20
		end
		for s = 1, d do
			aa = a * (d-s) / 20
			xp3 = xp-(xp-xp2)*s/d
			yp3 = yp-(yp-yp2)*s/d
			obj.draw (xp3+xc, yp3+yc, 1, aa)
		end

		-- 点の描画
		obj.draw(xp+xc, yp+yc, 1, a)
end

obj.load ("tempbuffer");

obj.effect ("Emission", "Strength", 75, "Diffusion", 0, "Threshold", 50, "vDiffuse", 0)
obj.effect ("Noise", "Strength", 50, "mode", 0, "type", 3)
