//Beautifier thanks to Ultima
task Concentration(x,y,duration,radius,density,turn,ap,blend,R,G,B,graphic){
	ChargeCircle(x,y,duration,R,G,B,blend);
	loop((duration-duration/1.2)/2){
		let n = 2*density;
		let a = rand(0,360);
		loop(n){
			DoSpriteThing(x,y,duration,a,radius,turn,ap,blend,R,G,B,graphic);
			a+=360/n;
		}
		wait(4);
	}
}

task DoSpriteThing(x,y,duration,a,radius,turn,ap,blend,R,G,B,graphic){
	let c = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(c,GetCurrentScriptDirectory ~ "FX/" ~ IntToString(graphic) ~ ".png");
	Obj_SetRenderPriorityI(c,70);
	ObjSprite2D_SetSourceRect(c,0,0,256,256);
	ObjSprite2D_SetDestRect(c,-128,-128,128,128);
	ObjSprite2D_SetDestCenter(c);
	ObjRender_SetColor(c,R,G,B);
	ObjRender_SetBlendType(c,blend);
	ObjRender_SetAngleZ(c,rand(0,360));
	let co = 0;
	let sc = 1;
	let al = 0;
	let r = radius+rand(10,-10);
	let shd = duration/2;
	let tp = rand(turn,-turn);
	let apd = rand(ap,-ap);
	loop(shd){
		ObjRender_SetPosition(c,x+r*cos(a),y+r*sin(a),0);
		ObjRender_SetAngleZ(c,ObjRender_GetAngleZ(c)+tp);
		ObjRender_SetAlpha(c,al);
		ObjRender_SetScaleXYZ(c,sc,sc,0);
		a+=apd;
		r-=radius/shd;
		sc-=1/shd;
		al+=255/shd;
		co++;
		yield;
	}
	Obj_Delete(c);
}

task ChargeCircle(x,y,duration,R,G,B,blend){
	let c = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(c,70);
	ObjPrim_SetTexture(c,GetCurrentScriptDirectory ~ "FX/ConcentrationCircle.png");
	ObjSprite2D_SetSourceRect(c,0,0,256,256);
	ObjSprite2D_SetDestRect(c,-128,-128,128,128);
	ObjSprite2D_SetDestCenter(c);
	ObjRender_SetColor(c,R,G,B);
	ObjRender_SetBlendType(c,blend);
	ObjRender_SetPosition(c,x,y,0);
	let sc = 2;
	let a = 0;
	loop(duration){
		ObjRender_SetScaleXYZ(c,sc,sc,0);
		ObjRender_SetAlpha(c,a);
		sc -= 2/duration;
		a += 255/duration;
		yield;
	}
	Obj_Delete(c);
}

task ConcentrationExplosion(x,y,duration,radius,density,turn,blend,R,G,B,graphic){
	ExplodeCircle(x,y,duration,R,G,B,blend);
	let n = density*4;
	let a = rand(0,360);
	loop(n){
			loop(density){DoSpriteThingExplode(x,y,duration,a,radius,turn,blend,R,G,B,graphic);
			a+=360/n;
		}
	}
}

task ExplodeCircle(x,y,duration,R,G,B,blend){
	let c = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(c,70);
	ObjPrim_SetTexture(c,GetCurrentScriptDirectory ~ "FX/ConcentrationCircle.png");
	ObjSprite2D_SetSourceRect(c,0,0,256,256);
	ObjSprite2D_SetDestRect(c,-128,-128,128,128);
	ObjSprite2D_SetDestCenter(c);
	ObjRender_SetColor(c,R,G,B);
	ObjRender_SetBlendType(c,blend);
	ObjRender_SetPosition(c,x,y,0);
	let sc = 0;
	let a = 255; 
	let ad = duration*3.5; let hd = duration*4;
	loop(duration){
		ObjRender_SetScaleXYZ(c, sc, sc, 0);
		ObjRender_SetAlpha(c, a);
		sc += 2/ad;
		a -= 255/hd;
		yield;
	}
	Obj_Delete(c);
}

task DoSpriteThingExplode(x,y,duration,a,radius,turn,blend,R,G,B,graphic){
	let c = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(c,GetCurrentScriptDirectory ~ "FX/" ~ IntToString(graphic) ~ ".png");
	Obj_SetRenderPriorityI(c,70);
	ObjSprite2D_SetSourceRect(c,0,0,256,256);
	ObjSprite2D_SetDestRect(c,-128,-128,128,128);
	ObjSprite2D_SetDestCenter(c);
	ObjRender_SetColor(c,R,G,B);
	ObjRender_SetBlendType(c,blend);
	radius+=rand(10,50);
	let co = 0;
	let sc = 0;
	let al = 255;
	let r = 0;
	let shd = duration/2;
	let tp = rand(turn,-turn);
	let iz = rand(0,360);
	loop(shd){
		ObjRender_SetPosition(c,x+r*cos(a),y+r*sin(a),0);
		ObjRender_SetAngleZ(c,iz+tp);
		ObjRender_SetAlpha(c,al);
		ObjRender_SetScaleXYZ(c,sc,sc,0);
		r+=radius/shd;
		sc+=1/shd;
		al-=255/shd;
		co++;
		yield;
	}
	Obj_Delete(c);
}