Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Drawing = {}
- Drawing.Services = {
- TextService = game:GetService("TextService"),
- RunService = game:GetService("RunService")
- }
- Drawing.Colours = {
- Red = Color3.fromRGB(255,0,0),
- Green = Color3.fromRGB(0,255,0),
- Blue = Color3.fromRGB(0,0,255),
- Pink = Color3.fromRGB(215,0,255),
- White = function(Value)
- return Value and Color3.fromRGB(Value,Value,Value) or Color3.fromRGB(255,255,255)
- end,
- Black = function(Value)
- return Value and Color3.fromRGB(Value, Value, Value) or Color3.fromRGB(0,0,0)
- end
- }
- local ValidTypes = {
- "line",
- "text",
- "circle",
- "square",
- "quad",
- "triangle"
- }
- local function TableContains(Table, Value)
- for _, TableValue in next, Table do
- if TableValue:sub(1, #Value):lower() == Value:lower() then
- return TableValue
- end
- end
- return false
- end
- function Angle(vectorA, vectorB)
- return math.acos(vectorA.Unit:Dot(vectorB.Unit))
- end
- local function GetUserResolution()
- local IsStudio = Drawing.Services.RunService:IsStudio()
- local ScreenGui = Instance.new("ScreenGui")
- ScreenGui.Parent = IsStudio and game.Players.LocalPlayer.PlayerGui or game:GetService("CoreGui")
- local Size = ScreenGui.AbsoluteSize
- ScreenGui:Destroy()
- return Size
- end
- function Drawing.new(Type)
- --[[
- Types:
- - Line
- - Text
- - Circle
- - Square
- - Quad
- - Triangle
- ]]
- local TargetType = TableContains(ValidTypes, Type)
- assert(TargetType, "Invalid type: '"..Type.."'.")
- if TargetType == "line" then
- local ProxyProperties = {
- Visible = true,
- Transparency = 0,
- Color = Drawing.Colours.White(),
- Thickness = 5,
- From = Vector2.new(0,0),
- To = Vector2.new(0,0)
- }
- local LinePart = Instance.new("ImageLabel")
- LinePart.Image = "rbxassetid://3570695787"
- LinePart.ScaleType = Enum.ScaleType.Slice
- LinePart.SliceCenter = Rect.new(100,100,100,100)
- LinePart.SliceScale = 1
- LinePart.BackgroundTransparency = 1
- LinePart.AnchorPoint = Vector2.new(0.5, 0.5)
- local LineProperties = {
- Functions = {
- Visible = function(self, bool)
- ProxyProperties.Visible = bool
- self.Visible = bool
- end,
- Transparency = function(self, float)
- ProxyProperties.Transparency = float
- self.ImageTransparency = ProxyProperties.Transparency
- end,
- Color = function(self, color3)
- ProxyProperties.Color = color3
- self.ImageColor3 = ProxyProperties.Color
- end,
- Thickness = function(self, value)
- ProxyProperties.Thickness = value
- self.Size = UDim2.fromOffset(ProxyProperties.Thickness, self.AbsoluteSize.Y)
- end,
- From = function(self, value)
- ProxyProperties.From = value
- local Position = (ProxyProperties.From + ProxyProperties.To) / 2
- self.Position = UDim2.fromOffset(Position.X, Position.Y)
- self.Size = UDim2.fromOffset(ProxyProperties.Thickness,(ProxyProperties.To - ProxyProperties.From).magnitude)
- local DY = ProxyProperties.To.Y - ProxyProperties.From.Y
- local DX = ProxyProperties.To.X - ProxyProperties.From.X
- local Delta = math.atan(DY/DX) * (180 / math.pi)
- self.Rotation = Delta + 90
- end,
- To = function(self, value)
- ProxyProperties.To = value
- local Position = (ProxyProperties.From + ProxyProperties.To) / 2
- self.Position = UDim2.fromOffset(Position.X, Position.Y)
- self.Size = UDim2.fromOffset(ProxyProperties.Thickness,(ProxyProperties.To - ProxyProperties.From).magnitude)
- local DY = ProxyProperties.To.Y - ProxyProperties.From.Y
- local DX = ProxyProperties.To.X - ProxyProperties.From.X
- local Delta = math.atan(DY/DX) * (180 / math.pi)
- self.Rotation = Delta + 90
- end
- },
- Remove = function()
- LinePart.Visible = false
- LinePart:Destroy()
- end
- }
- local MetaTable = {
- __newindex = function(self, index, value)
- if self.Functions[index] then
- return self.Functions[index](LinePart, value)
- else
- LinePart[index] = value
- end
- end,
- __index = function(self, index)
- local property = rawget(self, index)
- if not property then
- return rawget(ProxyProperties, index)
- else
- return property
- end
- end
- }
- setmetatable(LineProperties, MetaTable)
- return LineProperties
- elseif TargetType == "text" then
- local ProxyProperties = {
- Visible = true,
- Transparency = 0,
- Color = Drawing.Colours.White(),
- Thickness = 5,
- Text = "",
- Size = 14,
- Center = false,
- Outline = false,
- OutlineColor = Drawing.Colours.Black(),
- Position = Vector2.new(0,0),
- Font = Enum.Font.SourceSans
- }
- local TextPart = Instance.new("TextLabel")
- TextPart.Text = "Text"
- TextPart.BackgroundTransparency = 1
- local TextProperties = {
- Functions = {
- Visible = function(self, bool)
- ProxyProperties.Visible = bool
- TextPart.Visible = bool
- end,
- Center = function(self, bool)
- ProxyProperties.Center = bool
- end,
- Transparency = function(self, float)
- ProxyProperties.Transparency = float
- self.TextTransparency = ProxyProperties.Transparency
- end,
- Color = function(self, color3)
- ProxyProperties.Color = color3
- self.TextColor3 = ProxyProperties.Color
- end,
- Thickness = function(self, value)
- ProxyProperties.Thickness = value
- self.Size = UDim2.fromOffset(ProxyProperties.Thickness, self.AbsoluteSize.Y)
- end,
- Size = function(self, value)
- ProxyProperties.Size = value
- self.TextSize = ProxyProperties.Size
- end,
- Outline = function(self, bool)
- ProxyProperties.Outline = bool
- self.TextStrokeTransparency = ProxyProperties.Outline and 0 or 1
- end,
- OutlineColor = function(self, color3)
- ProxyProperties.OutlineColor = color3
- self.TextStrokeColor3 = ProxyProperties.OutlineColor
- end,
- Position = function(self, vector2)
- local TextSizeX = Drawing.Services.TextService:GetTextSize(ProxyProperties.Text, ProxyProperties.Size, ProxyProperties.Font, Vector2.new(0,0)).X
- ProxyProperties.Position = vector2
- self.Position = UDim2.fromOffset(ProxyProperties.Position.X-(TextSizeX/4), ProxyProperties.Position.Y)
- end,
- Font = function(self, variant)
- ProxyProperties.Font = variant
- self.Font = ProxyProperties.Font
- end,
- Text = function(self, string)
- local TextSizeX = Drawing.Services.TextService:GetTextSize(string, ProxyProperties.Size, ProxyProperties.Font, Vector2.new(0,0)).X
- ProxyProperties.Size = UDim2.fromOffset(TextSizeX, ProxyProperties.Size)
- self.Size = ProxyProperties.Size
- ProxyProperties.Text = string
- self.Text = ProxyProperties.Text
- end
- },
- Remove = function()
- TextPart.Visible = false
- TextPart:Destroy()
- end
- }
- local MetaTable = {
- __newindex = function(self, index, value)
- if rawget(rawget(self, "Functions"), index) then
- return self.Functions[index](TextPart, value)
- else
- TextPart[index] = value
- end
- end,
- __index = function(self, index)
- local check = rawget(self, index)
- if not check then
- local newcheck = TextPart[index]
- if newcheck then
- return newcheck
- else
- return nil
- end
- else
- return check
- end
- end
- }
- setmetatable(TextProperties, MetaTable)
- return TextProperties
- elseif TargetType == "circle" then
- local ProxyProperties = {
- Visible = true,
- Transparency = 0,
- Color = Drawing.Colours.White(),
- Thickness = 5,
- NumSides = 360,
- Filled = false,
- Position = Vector2.new(0,0),
- Radius = 100,
- Parent = script.Parent.Parent
- }
- local function EV(V2)
- return UDim2.fromOffset(V2.X, V2.Y)
- end
- local SidesContainer = Instance.new("Frame")
- SidesContainer.BackgroundTransparency = 1
- SidesContainer.Position = EV(ProxyProperties.Position)
- SidesContainer.Size = UDim2.fromOffset(ProxyProperties.Radius, ProxyProperties.Radius)
- local function Render(value)
- ProxyProperties.NumSides = value
- SidesContainer:Destroy()
- SidesContainer = Instance.new("Frame")
- SidesContainer.Name = "SidesContainer"
- SidesContainer.BackgroundTransparency = 1
- local GoPosition = EV(ProxyProperties.Position) - EV(Vector2.new(ProxyProperties.Radius/ProxyProperties.Thickness, ProxyProperties.Radius/ProxyProperties.Thickness))
- SidesContainer.Position = GoPosition
- SidesContainer.Size = UDim2.fromOffset(ProxyProperties.Radius, ProxyProperties.Radius)
- SidesContainer.Parent = ProxyProperties.Parent
- local Positions = {}
- local Step = 360 / value
- for I = 1, 360, Step do
- local GhostContainer = Instance.new("Frame")
- GhostContainer.Name = "GhostContainer"
- GhostContainer.BackgroundTransparency = 1
- GhostContainer.Size = UDim2.fromScale(1,1)
- GhostContainer.AnchorPoint = Vector2.new(0.5,0.5)
- GhostContainer.Position = UDim2.fromScale(0.5,0.5)
- GhostContainer.Rotation = I
- GhostContainer.Parent = SidesContainer
- local Pixel = Instance.new("Frame")
- Pixel.Name = "Pixel"
- Pixel.Size = UDim2.fromOffset(ProxyProperties.Thickness, ProxyProperties.Thickness)
- Pixel.Position = UDim2.new(0.5,-ProxyProperties.Thickness/2)
- Pixel.BackgroundTransparency = 1
- Pixel.Parent = GhostContainer
- table.insert(Positions, Pixel.AbsolutePosition)
- GhostContainer:Destroy()
- end
- for I, P in next, Positions do
- local Next = Positions[I + 1] or Positions[1]
- local NewLine = Drawing.new("li")
- NewLine.From = P - SidesContainer.AbsolutePosition
- NewLine.To = Next - SidesContainer.AbsolutePosition
- NewLine.Thickness = ProxyProperties.Thickness
- NewLine.Color = ProxyProperties.Color
- NewLine.Transparency = ProxyProperties.Transparency
- NewLine.Parent = SidesContainer
- end
- end
- local CircleProperties = {
- Functions = {
- Visible = function(self, bool)
- ProxyProperties.Visible = bool
- for _, E in next, SidesContainer:GetChildren() do
- E.Visible = ProxyProperties.Visible
- end
- end,
- Transparency = function(self, float)
- ProxyProperties.Transparency = float
- for _, E in next, SidesContainer:GetChildren() do
- E.BackgroundTransparency = ProxyProperties.Transparency
- end
- end,
- Color = function(self, color3)
- ProxyProperties.Color = color3
- for _, E in next, SidesContainer:GetChildren() do
- E.BackgroundColor3 = ProxyProperties.Color
- end
- end,
- Thickness = function(self, value)
- ProxyProperties.Thickness = value
- for _, E in next, SidesContainer:GetChildren() do
- E.Size = UDim2.fromOffset(ProxyProperties.Thickness, E.AbsoluteSize.Y)
- end
- end,
- Position = function(self, vector2)
- ProxyProperties.Position = vector2
- Render(ProxyProperties.NumSides)
- end,
- NumSides = function(self, value)
- ProxyProperties.NumSides = value
- Render(value)
- end,
- Radius = function(self, value)
- ProxyProperties.Radius = value
- Render(ProxyProperties.NumSides)
- end,
- Parent = function(self, instance)
- ProxyProperties.Parent = instance
- SidesContainer.Parent = ProxyProperties.Parent
- end
- },
- Remove = function()
- SidesContainer.Visible = false
- SidesContainer:Destroy()
- end
- }
- local MetaTable = {
- __newindex = function(self, index, value)
- if self.Functions[index] then
- return self.Functions[index](nil, value)
- else
- SidesContainer[index] = value
- end
- end,
- __index = function(self, index)
- local property = rawget(self, index)
- if not property then
- return rawget(ProxyProperties, index)
- else
- return property
- end
- end
- }
- setmetatable(CircleProperties, MetaTable)
- return CircleProperties
- elseif TargetType == "square" then
- local ProxyProperties = {
- Visible = true,
- Transparency = 0,
- Color = Drawing.Colours.White(),
- Thickness = 5,
- Size = 100,
- Position = Vector2.new(0,0),
- Filled = false
- }
- end
- end
- return Drawing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement