local N={}N.__index=N local f=Vector2.new(0,.85)function N.setGravity(N)f=N end function N.createParticle(f,z,j)local t={}setmetatable(t,N)local R=z.X if R<0 then R=R*-1 end local Y=0-R z=Vector2.new(z.X,z.Y+Y*.75)t.EmitterPosition=f t.EmitterPower=z t.Position=Vector2.new(0,0)t.Power=z t.Color=getColor()local function e()local N=shapes[math.random(#shapes)]:Clone()N.Size=UDim2.new(t.DefaultSize,0,t.DefaultSize,0)N.ImageColor3=t.Color N.Parent=j N.Rotation=math.random(360)N.Visible=true N.ZIndex=100 return N end t.DefaultSize=math.random(1,2)/20 t.Label=e()t.Size=1 t.Side=-1 t.OutOfBounds=false t.Enabled=true t.Cycles=0 return t end function N.Update(N)if N.Enabled and N.OutOfBounds then N.Position=Vector2.new(0,0)N.Power=Vector2.new((N.EmitterPower.X+math.random(10))-5,(N.EmitterPower.Y+math.random(10))-5)N.Cycles=N.Cycles+1 end if not N.Enabled and N.OutOfBounds then return end local z,j,t=N.EmitterPosition,N.Position,N.Power local R=N.Label if R then local Y=Vector2.new(j.X-t.X,j.Y-t.Y)local e=Vector2.new(t.X/1.09-f.X,t.Y/1.1-f.Y)local Z=Camera.ViewportSize R.Position=UDim2.new(z.X,Y.X,z.Y,Y.Y)N.OutOfBounds=R.AbsolutePosition.X>Z.X and f.X>0 or R.AbsolutePosition.Y>Z.Y and f.Y>0 or R.AbsolutePosition.X<0 and f.X<0 or R.AbsolutePosition.Y<0 and f.Y<0 N.Position,N.Power=Y,e end end function N.Toggle(N)N.Enabled=not N.Enabled end return N
-- Main Functions --
local _Confetti = {}
_Confetti.__index = _Confetti

-- Set Gravity --
local gravity = Vector2.new(0, 0.85)
function _Confetti.setGravity(paramVec2)
	gravity = paramVec2
end

-- Create A Confetti Particle --
function _Confetti.createParticle(paramEmitter, paramForce, paramParent)
	local _Particle = {}
	setmetatable(_Particle, _Confetti)

	local xforce = paramForce.X
	if xforce < 0 then
		xforce = xforce * -1
	end
	local distanceFromZero = 0 - xforce
	paramForce = Vector2.new(paramForce.X, paramForce.Y + (distanceFromZero * 0.75))

	_Particle.EmitterPosition = paramEmitter
	_Particle.EmitterPower = paramForce
	_Particle.Position = Vector2.new(0, 0)
	_Particle.Power = paramForce
	_Particle.Color = getColor()

	local function getParticle()
		local label = shapes[math.random(#shapes)]:Clone()
		label.Size = UDim2.new(_Particle.DefaultSize, 0, _Particle.DefaultSize, 0)
		label.ImageColor3 = _Particle.Color
		label.Parent = paramParent
		label.Rotation = math.random(360)
		label.Visible = true
		label.ZIndex = 100
		return label
	end

	_Particle.DefaultSize = (math.random(1, 2)) / 20
	_Particle.Label = getParticle()
	_Particle.Size = 1
	_Particle.Side = -1
	_Particle.OutOfBounds = false
	_Particle.Enabled = true
	_Particle.Cycles = 0

	return _Particle
end

-- Update Postion Of Confettis --
function _Confetti:Update()
	if self.Enabled and self.OutOfBounds then
		self.Position = Vector2.new(0, 0)
		self.Power = Vector2.new(self.EmitterPower.X + math.random(10) - 5, self.EmitterPower.Y + math.random(10) - 5)
		self.Cycles = self.Cycles + 1
	end
	if not self.Enabled and self.OutOfBounds then
		return
	end
	local startPosition, currentPosition, currentPower = self.EmitterPosition, self.Position, self.Power
	local imageLabel = self.Label

	if imageLabel then
		local newPosition = Vector2.new(currentPosition.X - currentPower.X, currentPosition.Y - currentPower.Y)
		local newPower = Vector2.new((currentPower.X / 1.09) - gravity.X, (currentPower.Y / 1.1) - gravity.Y)
		local ViewportSize = Camera.ViewportSize
		imageLabel.Position = UDim2.new(startPosition.X, newPosition.X, startPosition.Y, newPosition.Y)
		self.OutOfBounds = (imageLabel.AbsolutePosition.X > ViewportSize.X and gravity.X > 0)
			or (imageLabel.AbsolutePosition.Y > ViewportSize.Y and gravity.Y > 0)
			or (imageLabel.AbsolutePosition.X < 0 and gravity.X < 0)
			or (imageLabel.AbsolutePosition.Y < 0 and gravity.Y < 0)
		self.Position, self.Power = newPosition, newPower

		--[[
			if (newPower.Y < 0) then
				if (self.Size <= 0) then
					self.Side = 1
					imageLabel.ImageColor3 = self.Color
				end
				if (self.Size >= self.DefaultSize) then 
					self.Side = -1
					imageLabel.ImageColor3 = Color3.new(self.Color.r * 0.65, self.Color.g * 0.65, self.Color.b * 0.65)
				end
			end
			--]]
	end
end

-- Stops Confetti --
function _Confetti:Toggle()
	self.Enabled = not self.Enabled
end

return _Confetti
