
let dirCurrent = GetCurrentScriptDirectory();

@Initialize
{
	TBackgroundCenter();
	InitFrame();
//	TScore();
//	TGraze();
	TPlayerLife();
	TPlayerSpell();
	TPlayerSpirit();
	TBossLife();
	TBossTimer();
}


@MainLoop
{
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_START_BOSS_SPELL)
	{
		let path = dirCurrent ~ "System_MagicCircle.txt";
		let id = LoadScript(path);
		StartScript(id);
	}
	case(EV_GAIN_SPELL)
	{
		let objScene = GetEnemyBossSceneObjectID();
		let score = ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE);
		TGainSpell(score);
	}
}

//----------------------------------------------------
//枠外の背景表示
//----------------------------------------------------
function InitFrame()
{
	//let path = GetCurrentScriptDirectory() ~ "img/Default_SystemBackground.png";
	let path = GetCurrentScriptDirectory() ~ "img/system.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0);
	ObjSprite2D_SetSourceRect(obj, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
	ObjSprite2D_SetDestRect(obj, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}


task TBackgroundCenter
{
	//let imgBer = GetTransitionRenderTargetName();
	let imgBer = GetCurrentScriptDirectory() ~ "img/system2.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgBer);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,80);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, 0, 0, 0);
	ObjPrim_SetVertexPosition(obj, 1, 448,0, 0);
	ObjPrim_SetVertexPosition(obj, 2, 448, 464, 0);
	ObjPrim_SetVertexPosition(obj, 3, 0, 464, 0);

	ObjPrim_SetVertexUVT(obj, 0, 32, 16);
	ObjPrim_SetVertexUVT(obj, 1, 480, 16);
	ObjPrim_SetVertexUVT(obj, 2, 480, 480);
	ObjPrim_SetVertexUVT(obj, 3, 32, 480);

/*
	ObjPrim_SetVertexPosition(obj, 0, 32, 16, 0);
	ObjPrim_SetVertexPosition(obj, 1, 480,16, 0);
	ObjPrim_SetVertexPosition(obj, 2, 480, 464, 0);
	ObjPrim_SetVertexPosition(obj, 3, 32, 464, 0);

	ObjPrim_SetVertexUVT(obj, 0, 32, 16);
	ObjPrim_SetVertexUVT(obj, 1, 480, 16);
	ObjPrim_SetVertexUVT(obj, 2, 480, 464);
	ObjPrim_SetVertexUVT(obj, 3, 32, 464);
*/
	ObjRender_SetPosition(obj,0,0,0);

	let alpha=255;

	ObjRender_SetAlpha(obj, alpha);
	yield;
	while(GetCommonData("Title",false)){yield;}
	loop(30)
	{
	alpha-=255/30;

	ObjRender_SetAlpha(obj, alpha);
	yield;
	}
	Obj_Delete(obj);
}


//----------------------------------------------------
//スコア表示
//----------------------------------------------------
task TScore()
{
	//Score文字列
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, "Score");
	ObjText_SetFontSize(objScore, 20);
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 255, 255);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore,128, 128, 128);
	ObjText_SetFontBorderWidth(objScore, 2);
	Obj_SetRenderPriority(objScore, 0.01);
	ObjRender_SetX(objScore, 428);
	ObjRender_SetY(objScore, 48);

	//得点
	let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_SystemDigit.png";
	let count = 12;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.1);
	ObjRender_SetY(obj, 72);

	while(true)
	{
		let score = GetScore();
		score = min(score, 999999999999);
		let listNum = DigitToArray(score, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 440 + iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, num * 36, 0, (num + 1) * 36, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 24);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}
}

//----------------------------------------------------
//Graze表示
//----------------------------------------------------
task TGraze()
{
	//Graze文字列
	let objGraze = ObjText_Create();
	ObjText_SetText(objGraze, "Graze");
	ObjText_SetFontSize(objGraze, 20);
	ObjText_SetFontBold(objGraze, true);
	ObjText_SetFontColorTop(objGraze, 255, 255, 255);
	ObjText_SetFontColorBottom(objGraze, 255, 255, 255);
	ObjText_SetFontBorderType(objGraze, BORDER_FULL);
	ObjText_SetFontBorderColor(objGraze,128, 128, 128);
	ObjText_SetFontBorderWidth(objGraze, 2);
	Obj_SetRenderPriority(objGraze, 0.01);
	ObjRender_SetX(objGraze, 428);
	ObjRender_SetY(objGraze, 98);

	//得点
	let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_SystemDigit.png";
	let count = 5;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.1);
	ObjRender_SetY(obj, 122);

	while(true)
	{
		let graze = GetGraze();
		graze = min(graze, 99999);
		let listNum = DigitToArray(graze, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 440 + iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, num * 36, 0, (num + 1) * 36, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 24);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}
}

//----------------------------------------------------
//残機表示
//----------------------------------------------------
task TPlayerLife
{
	//life文字列
	let objText = ObjText_Create();
	ObjText_SetText(objText, "Life");
	ObjText_SetFontSize(objText, 16);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 255);
	ObjText_SetFontBorderType(objText, BORDER_NONE);
	ObjText_SetFontBorderColor(objText,128, 128, 128);
	ObjText_SetFontBorderWidth(objText, 0);
	ObjText_SetFontType(objText,"ＭＳ 明朝");
	Obj_SetRenderPriority(objText, 0.01);
	ObjRender_SetX(objText, 428+60);
	ObjRender_SetY(objText, 26);

	//残機
	//let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_SystemDigit.png";
	let pathDigit = GetCurrentScriptDirectory() ~ "img/StatusStar.png";
	let count = 8;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	//ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.1);
	ObjRender_SetY(obj, 44);

	while(true)
	{
		let point = GetPlayerLife()+1;
		point = min(point, 99);
		let listNum = DigitToArray(point, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. point)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 426+60 + iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, 0, 0, 16, 16);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 16);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}
}

//----------------------------------------------------
//残スペル表示
//----------------------------------------------------
task TPlayerSpell
{
	//Spell文字列
	let objText = ObjText_Create();
	ObjText_SetText(objText, "Spell Card Point");
	ObjText_SetFontSize(objText, 16);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 255);
	ObjText_SetFontBorderType(objText, BORDER_NONE);
	ObjText_SetFontBorderColor(objText,128, 128, 128);
	ObjText_SetFontBorderWidth(objText, 0);
	ObjText_SetFontType(objText,"ＭＳ 明朝");
	Obj_SetRenderPriority(objText, 0.01);
	ObjRender_SetX(objText, 428+60);
	ObjRender_SetY(objText, 80);

	//スペル
	let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_SystemDigit.png";
	let count = 2;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.1);
	ObjRender_SetY(obj, 226);

	while(true)
	{
		let point = GetPlayerSpell();
		point = min(point, 99);
		let listNum = DigitToArray(point, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 440 + iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, num * 36, 0, (num + 1) * 36, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 24);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}
}

task TPlayerSpirit
{
	//Spell文字列
	let objText = ObjText_Create();
	ObjText_SetText(objText, "Spirit Point");
	ObjText_SetFontSize(objText, 16);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 255);
	ObjText_SetFontBorderType(objText, BORDER_NONE);
	ObjText_SetFontBorderColor(objText,128, 128, 128);
	ObjText_SetFontBorderWidth(objText, 0);
	ObjText_SetFontType(objText,"ＭＳ 明朝");
	Obj_SetRenderPriority(objText, 0.01);
	ObjRender_SetX(objText, 428+60);
	ObjRender_SetY(objText, 120);

	//スペル
	let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_SystemDigit.png";
	let count = 2;

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.1);
	ObjRender_SetY(obj, 226);

	while(true)
	{
		let point = GetPlayerSpell();
		point = min(point, 99);
		let listNum = DigitToArray(point, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			ObjRender_SetX(obj, 440 + iObj * 14);
			ObjSpriteList2D_SetSourceRect(obj, num * 36, 0, (num + 1) * 36, 32);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 16, 24);
			ObjSpriteList2D_AddVertex(obj);
		}
		yield;
	}
}

//----------------------------------------------------
//ボスのライフ表示
//----------------------------------------------------

task TBossLife
{
	let HueCount=0;
	let Color=HueDifine(HueCount);
	let csd = GetMainStgScriptDirectory();

	let pathStar = csd ~ "img/Star.png";

	let pathTBer = csd ~ "img/ber2.png";
	let TBerscale=0;

	let objTBer = ObjPrim_Create(OBJ_PRIMITIVE_2D); //2D頂点ブジェクト生成
	ObjPrim_SetPrimitiveType(objTBer, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(objTBer,4);
	Obj_SetRenderPriority(objTBer, 0.7); //描画優先度を設定
	ObjPrim_SetTexture(objTBer, pathTBer); //テクスチャを設定

	ObjRender_SetPosition(objTBer,200-157,0+10,0);


	let path = GetCurrentScriptDirectory() ~ "img/Default_System.png";

	let Alpha=0.6;
	let R=255;let G=255;let B=255;
	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathTBer);
	Obj_SetRenderPriority(obj, 0.71);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

	let objLDiv = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(objLDiv, path);
	Obj_SetRenderPriority(objLDiv, 0.71);
	//ObjRender_SetBlendType(objLDiv, BLEND_ADD_RGB);

	let objStar = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(objStar, pathStar);
	Obj_SetRenderPriority(objStar, 0.71);
	ObjRender_SetPosition(objStar,200-192,0+10,0);

	ObjRender_SetPosition(obj,200-157,0+10,0);

	let pathDigit = csd ~ "img/Number.png";

	let objNum = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(objNum, pathDigit);
	ObjRender_SetBlendType(objNum, BLEND_ADD_RGB);
	Obj_SetRenderPriority(objNum, 0.75);

	ObjRender_SetPosition(objNum,200-192,0+10,0);

	let lastRemStep = -1;
	let lifeRateRender = 0;

	let Xangle=0;
	let Yangle=0;
	let Zangle=0;
	let objScene = ID_INVALID;
	loop
	{
		objScene = GetEnemyBossSceneObjectID();
		ObjSpriteList2D_ClearVertexCount(obj);
		ObjSpriteList2D_ClearVertexCount(objLDiv);
		ObjSpriteList2D_ClearVertexCount(objTBer);
		ObjSpriteList2D_ClearVertexCount(objStar);
		ObjSpriteList2D_ClearVertexCount(objNum);

		if(objScene != ID_INVALID)
		{
			RenderLife();
		}
		yield;
	}


	function RenderLife()
	{
		//残りステップ
		let countRemStep = ObjEnemyBossScene_GetInfo(objScene, INFO_REMAIN_STEP_COUNT);
		if(lastRemStep != countRemStep)
		{
			//ステップが変化
			lifeRateRender = 0;
		}

		//ライフ表示
		let lifeTotalMax = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_MAX_LIFE);
		let lifeTotal = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_TOTAL_LIFE);
		let lifeRate = lifeTotal / lifeTotalMax*lifeRateRender;

		ObjRender_SetColor(obj,(255-Color[0]/5)*Alpha, (200-Color[1]/5)*Alpha,(255-Color[2]/5)*Alpha);


		//ObjSpriteList2D_SetSourceRect(obj, 1, 1, 127, 11);
		ObjSpriteList2D_SetSourceRect(obj, 6, 51, 148, 57);
		ObjSpriteList2D_SetDestRect(obj, 0, -3, 0 + 290 * lifeRate, 3);
		ObjSpriteList2D_AddVertex(obj);

		//ライフの区切り表示
		ObjSpriteList2D_SetSourceRect(objLDiv, 132, 1, 137, 11);
		//ObjSpriteList2D_SetSourceRect(objLDiv, 149, 37, 152, 47);
		let listLifeDiv = [0] ~ ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_LIFE_RATE_LIST);
		ascent(iDiv in 0 .. length(listLifeDiv))
		{
			let rate = listLifeDiv[iDiv];
		//	if(rate!=1 && rate!=0)
		//	{
			let x = 43 + 290 * (1-rate);
			ObjSpriteList2D_SetDestRect(objLDiv, x-1, 5+1, x + 1, 13+1);
			ObjSpriteList2D_AddVertex(objLDiv);
		//	}
		}

		//残りステップ表示

		ObjRender_SetColor(objStar,150-Color[0]/10,255-Color[1]/10,200-Color[2]/10);
		ObjRender_SetAngleXYZ(objStar,Xangle,Yangle,Zangle);
		Zangle+=3;

		ObjSpriteList2D_SetSourceRect(objStar, 0,0, 16, 16);
		ObjSpriteList2D_SetDestRect(objStar, -8, -8, 0 + 8, 8);
		ObjSpriteList2D_AddVertex(objStar);

		ObjSprite2D_SetDestCenter(objTBer);

		ObjPrim_SetVertexPosition(objTBer,	0, 0	, -6,0);
		ObjPrim_SetVertexPosition(objTBer,	1, 290	, -6,0);
		ObjPrim_SetVertexPosition(objTBer,	2, 290	, 6,0);
		ObjPrim_SetVertexPosition(objTBer,	3, 0	, 6,0);


		TBerscale=1.0*lifeRateRender*0;
		ObjRender_SetScaleXYZ(objTBer,TBerscale,0.8,1);
		ObjPrim_SetVertexUVT(objTBer, 0,  6,  37);
		ObjPrim_SetVertexUVT(objTBer, 1,  6+lifeRateRender*71*2, 37);
		ObjPrim_SetVertexUVT(objTBer, 2, 6+lifeRateRender*71*2,  47);
		ObjPrim_SetVertexUVT(objTBer, 3,6, 47);
let count=2;
		let timer = countRemStep;
		timer = min(timer, 9999);
		let listNum = DigitToArray(timer,count);

		ObjSpriteList2D_ClearVertexCount(objNum);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];

			ObjRender_SetScaleXYZ(objNum,1.0,1.0,1);
			ObjRender_SetX(objNum, 32 + iObj * 9.5-18.5);
			ObjRender_SetY(objNum, 2);

			ObjSpriteList2D_SetSourceRect(objNum, num * 48+6, 0+6, (num + 1) * 48+6, 48+6);
			ObjSpriteList2D_SetDestRect(objNum, 0, 0, 16, 16);
			ObjSpriteList2D_AddVertex(objNum);
		}

		Color=HueDifine(HueCount);
		HueCount+=3;
		lifeRateRender += 1/60;
		lifeRateRender = min(lifeRateRender, 1);
		lastRemStep = countRemStep;
	}
}


//----------------------------------------------------
//タイマー表示
//----------------------------------------------------

task TBossTimer
{
	let csd = GetMainStgScriptDirectory();

	//let pathDigit = GetCurrentScriptDirectory() ~ "img/Default_SystemDigit.png";

	let pathDigit = csd ~ "img/Number.png";

	let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
	ObjPrim_SetTexture(obj, pathDigit);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.75);
	ObjRender_SetY(obj, 0);
	let count = 4;

	let objScene = ID_INVALID;
	loop
	{
		objScene = GetEnemyBossSceneObjectID();
		ObjSpriteList2D_ClearVertexCount(obj);
		if(objScene != ID_INVALID)
		{
			RenderTimer();
		}
		yield;
	}

	function RenderTimer()
	{
		let timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMERF)*100/60;
		timer = min(timer, 9999);
		let listNum = DigitToArray(timer, count);

		ObjSpriteList2D_ClearVertexCount(obj);
		ascent(iObj in 0 .. count)
		{
			let num = listNum[iObj];
			if(iObj>=2)
			{
				ObjRender_SetScaleXYZ(obj,0.75,0.75,1);
				ObjRender_SetX(obj, 352 + iObj * 9.0-8);
				ObjRender_SetY(obj, 4.8);
			}
			else
			{
				ObjRender_SetScaleXYZ(obj,1.0,1.0,1);
				ObjRender_SetX(obj, 352 + iObj * 10.5-18.5);
				ObjRender_SetY(obj, 0);
			}
			ObjSpriteList2D_SetSourceRect(obj, num * 48+6, 0+6, (num + 1) * 48+6, 48+6);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 20, 20);
			ObjSpriteList2D_AddVertex(obj);
		}

			ObjRender_SetScaleXYZ(obj,1.0,1.0,1);
			ObjRender_SetX(obj, 354.5);
			ObjRender_SetY(obj, 0);
			ObjSpriteList2D_SetSourceRect(obj, 0 * 48+6, 0+6+48, (0 + 1) * 48+6, 48+6+48);
			ObjSpriteList2D_SetDestRect(obj, 0, 0, 20, 20);
			ObjSpriteList2D_AddVertex(obj);

		yield;
	}

}

//----------------------------------------------------
//スペルカード取得表示
//----------------------------------------------------
task TGainSpell(score)
{
	let objText = ObjText_Create();
	ObjText_SetText(objText, "Spell Card Bonus!");
	ObjText_SetFontSize(objText, 32);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 128, 128, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,255, 255, 255);
	ObjText_SetFontBorderWidth(objText, 1);
	Obj_SetRenderPriority(objText, 0.6);
	ObjRender_SetX(objText, 32);
	ObjRender_SetY(objText, 98);

	let strScore = "+" ~ IntToString(score);
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, strScore);
	ObjText_SetFontSize(objScore, 32);
	ObjText_SetFontBold(objScore, true);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 128, 128);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore,255, 255, 255);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.6);
	ObjRender_SetX(objScore, 180);
	ObjRender_SetY(objScore, 140);

	loop(120)
	{
		yield;
	}
	Obj_Delete(objText);
	Obj_Delete(objScore);
}

//----------------------------------------------------
//ユーティリティ
//----------------------------------------------------
function DigitToArray(let digit,let count)
{
	let res = [];
	digit = truncate(digit);

	loop
	{
		let tnum = truncate(digit % 10);
		digit /= 10;
		res = [tnum] ~ res;
		if(truncate(digit) == 0){break;}
	}

	loop(max(0, count - length(res)))
	{
		res = [0] ~ res;
	}

	return res;
}
function HueDifine(HueCount)
{
let ColorRed=0;
let ColorGreen=0;
let ColorBlue=0;
let MinColor=0;
while(HueCount>360){HueCount-=360;}
while(HueCount<=0){HueCount+=360;}
	if(0<HueCount && HueCount<=60)
	{
		ColorRed=255;
		ColorGreen=255*(HueCount)/60;
		ColorBlue=0;
	}
	else if(HueCount<=120)
	{
		ColorRed=255*(120-HueCount)/60;
		ColorGreen=255;
		ColorBlue=0;
	}
	else if(HueCount<=180)
	{
		ColorRed=0;
		ColorGreen=255;
		ColorBlue=255*(HueCount-120)/60;
	}
	else if(HueCount<=240)
	{
		ColorRed=0;
		ColorGreen=255*(240-HueCount)/60;
		ColorBlue=255;
	}
	else if(HueCount<=300)
	{
		ColorRed=255*(HueCount-240)/60;
		ColorGreen=0;
		ColorBlue=255;
	}
	else if(HueCount<=360)
	{
		ColorRed=255;
		ColorGreen=0;
		ColorBlue=255*(360-HueCount)/60;
	}
	return([ColorRed,ColorGreen,ColorBlue]);
}

