local r={BrickColor.new("\066\114\105\103\104\116 \121\101\108\108\111\119"),BrickColor.new("\066\114\105\103\104\116 \111\114\097\110\103\101"),BrickColor.new("\066\114\105\103\104\116 \114\101\100")}local P=require(((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101"))local v=P:GetResource("\069\120\116\101\114\110\097\108\085\116\105\108\046\078\101\120\117\115\073\110\115\116\097\110\099\101\046\078\101\120\117\115\079\098\106\101\099\116")local f=v:Extend()f:SetClassName("\084\114\101\101")function f.__new(f,r,P,v)f:InitializeSuper()local Q=Instance.new("\077\111\100\101\108")Q.Name="\084\114\101\101"Q.Parent=P f.TreeModel=Q f.RandomNumberGenerator=v local b=v:NextNumber(8,10)r=f:CreateWood(b,3,(r*CFrame.new(0,-1,0))*CFrame.Angles(v:NextNumber(-math.rad(5),math.rad(5)),0,v:NextNumber(-math.rad(5),math.rad(5))))r=f:CreateWood(b,3,r*CFrame.Angles(v:NextNumber(-math.rad(10),math.rad(10)),0,v:NextNumber(-math.rad(10),math.rad(10))))local A=v:NextInteger(3,4)for P=1,A,1 do local Q=(r*CFrame.Angles(0,(2*math.pi)*(P/A)+v:NextNumber(-math.rad(15),math.rad(15)),0))*CFrame.Angles(v:NextNumber(math.rad(40),math.rad(65)),v:NextNumber(-math.rad(15),math.rad(15)),0)Q=f:CreateWood(v:NextNumber(6,10),2,Q)for r=1,2,1 do local P=(Q*CFrame.Angles(0,math.pi*r+v:NextNumber(-math.rad(45),math.rad(45)),0))*CFrame.Angles(v:NextNumber(math.rad(30),math.rad(50)),0,0)P=f:CreateWood(v:NextNumber(4,6),1,P)f:CreateLeaves(v:NextNumber(12,16),P*CFrame.Angles(v:NextNumber(),v:NextNumber(),v:NextNumber()))end end end function f.CreatePart(b,r,P,v,f,Q)local A=Instance.new("\080\097\114\116")A.BrickColor=r A.Material=P A.Shape=Q or"\066\108\111\099\107"A.Size=v A.CFrame=f A.Anchored=true A.TopSurface="\083\109\111\111\116\104"A.BottomSurface="\083\109\111\111\116\104"A.Parent=b.TreeModel end function f.CreateWood(f,r,P,v)f:CreatePart(BrickColor.new("\066\114\111\119\110"),"\087\111\111\100",Vector3.new(r,P,P),(v*CFrame.new(0,r/2,0))*CFrame.Angles(0,0,math.pi/2),"\067\121\108\105\110\100\101\114")f:CreatePart(BrickColor.new("\066\114\111\119\110"),"\087\111\111\100",Vector3.new(P,P,P),(v*CFrame.new(0,r,0))*CFrame.Angles(0,0,math.pi/2),"\066\097\108\108")return v*CFrame.new(0,r,0)end function f.CreateLeaves(f,P,v)local Q=Vector3.new(P,P,P)f:CreatePart(r[f.RandomNumberGenerator:NextInteger(1,#r)],"\071\114\097\115\115",Q,v*CFrame.Angles(f.RandomNumberGenerator:NextNumber(),f.RandomNumberGenerator:NextNumber(),f.RandomNumberGenerator:NextNumber()))f:CreatePart(r[f.RandomNumberGenerator:NextInteger(1,#r)],"\071\114\097\115\115",Q*.8,v*CFrame.Angles(f.RandomNumberGenerator:NextNumber(),f.RandomNumberGenerator:NextNumber(),f.RandomNumberGenerator:NextNumber()))end function f.Destroy(r)r.TreeModel:Destroy()end return f
--[[
TheNexusAvenger

Generates a tree.
--]]

local LEAVE_COLORS = {
    BrickColor.new("Bright yellow"),
    BrickColor.new("Bright orange"),
    BrickColor.new("Bright red"),
}



local ReplicatedStorageProject = require(game:GetService("ReplicatedStorage"):WaitForChild("Project"):WaitForChild("ReplicatedStorage"))

local NexusObject = ReplicatedStorageProject:GetResource("ExternalUtil.NexusInstance.NexusObject")

local Tree = NexusObject:Extend()
Tree:SetClassName("Tree")



--[[
Creates a tree.
--]]
function Tree:__new(Center,Parent,RandomNumberGenerator)
    self:InitializeSuper()

    --Create the model.
    local TreeModel = Instance.new("Model")
    TreeModel.Name = "Tree"
    TreeModel.Parent = Parent
    self.TreeModel = TreeModel
    self.RandomNumberGenerator = RandomNumberGenerator

    --Create the trunk.
    local TrunkLength = RandomNumberGenerator:NextNumber(8,10)
	Center = self:CreateWood(TrunkLength,3,Center * CFrame.new(0,-1,0) * CFrame.Angles(RandomNumberGenerator:NextNumber(-math.rad(5),math.rad(5)),0,RandomNumberGenerator:NextNumber(-math.rad(5),math.rad(5))))
    Center = self:CreateWood(TrunkLength,3,Center * CFrame.Angles(RandomNumberGenerator:NextNumber(-math.rad(10),math.rad(10)),0,RandomNumberGenerator:NextNumber(-math.rad(10),math.rad(10))))
    
    --Create the branches.
	local TotalBranches = RandomNumberGenerator:NextInteger(3,4)
	for i = 1,TotalBranches do
		local BranchCenter = Center * CFrame.Angles(0,(2 * math.pi * (i/TotalBranches)) + RandomNumberGenerator:NextNumber(-math.rad(15),math.rad(15)),0) * CFrame.Angles(RandomNumberGenerator:NextNumber(math.rad(40),math.rad(65)),RandomNumberGenerator:NextNumber(-math.rad(15),math.rad(15)),0)
		BranchCenter = self:CreateWood(RandomNumberGenerator:NextNumber(6,10),2,BranchCenter)
		for j = 1,2 do
			local LeavesCenter = BranchCenter * CFrame.Angles(0,(math.pi * j) + RandomNumberGenerator:NextNumber(-math.rad(45),math.rad(45)),0) * CFrame.Angles(RandomNumberGenerator:NextNumber(math.rad(30),math.rad(50)),0,0)
			LeavesCenter = self:CreateWood(RandomNumberGenerator:NextNumber(4,6),1,LeavesCenter)
			self:CreateLeaves(RandomNumberGenerator:NextNumber(12,16),LeavesCenter * CFrame.Angles(RandomNumberGenerator:NextNumber(),RandomNumberGenerator:NextNumber(),RandomNumberGenerator:NextNumber()))
		end
	end
end

--[[
Creates a part in the tree model.
--]]
function Tree:CreatePart(Color,Material,Size,Center,Shape)
    local Part = Instance.new("Part")
	Part.BrickColor = Color
	Part.Material = Material
	Part.Shape = Shape or "Block"
	Part.Size = Size
	Part.CFrame = Center
	Part.Anchored = true
	Part.TopSurface = "Smooth"
	Part.BottomSurface = "Smooth"
	Part.Parent = self.TreeModel
end

--[[
Creates a wood part for the tree.
Returns the end CFrame.
--]]
function Tree:CreateWood(Length,Width,Center)
    self:CreatePart(BrickColor.new("Brown"),"Wood",Vector3.new(Length,Width,Width),Center * CFrame.new(0,Length/2,0) * CFrame.Angles(0,0,math.pi/2),"Cylinder")
	self:CreatePart(BrickColor.new("Brown"),"Wood",Vector3.new(Width,Width,Width),Center * CFrame.new(0,Length,0) * CFrame.Angles(0,0,math.pi/2),"Ball")
	return Center * CFrame.new(0,Length,0)
end

--[[
Creates a set of leaves for the tree.
--]]
function Tree:CreateLeaves(Width,Center)
    local Size = Vector3.new(Width,Width,Width)
	self:CreatePart(LEAVE_COLORS[self.RandomNumberGenerator:NextInteger(1,#LEAVE_COLORS)],"Grass",Size,Center * CFrame.Angles(self.RandomNumberGenerator:NextNumber(),self.RandomNumberGenerator:NextNumber(),self.RandomNumberGenerator:NextNumber()))
	self:CreatePart(LEAVE_COLORS[self.RandomNumberGenerator:NextInteger(1,#LEAVE_COLORS)],"Grass",Size * 0.8,Center * CFrame.Angles(self.RandomNumberGenerator:NextNumber(),self.RandomNumberGenerator:NextNumber(),self.RandomNumberGenerator:NextNumber()))
end

--[[
Destroys the tree.
--]]
function Tree:Destroy()
    self.TreeModel:Destroy()
end



return Tree