Guest User

Roblox Vector Shape Generator

a guest
Oct 1st, 2015
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. local Quality = 1
  2.  
  3. local function DrawTriangle(Parent,Points)
  4.     local function GetLinesFromPosY(PosY)
  5.         local function GetPoint(Num)
  6.             if Num > #Points then
  7.                 return Points[1]
  8.             end
  9.             return Points[Num]
  10.         end
  11.        
  12.         local Lines = {}
  13.         for i = 1, #Points do
  14.             local Point1,Point2 = GetPoint(i),GetPoint(i+1)
  15.             if (Point1.Y.Offset < PosY and Point2.Y.Offset >= PosY) then
  16.                 table.insert(Lines,{Point1,Point2})
  17.             elseif (Point2.Y.Offset < PosY and Point1.Y.Offset >= PosY) then
  18.                 table.insert(Lines,{Point2,Point1})
  19.             end
  20.         end
  21.        
  22.         return Lines
  23.     end
  24.  
  25.  
  26.  
  27.     local function Lerp(S,E,A)
  28.         return S + (E-S)*A
  29.     end
  30.    
  31.     local function DrawLine(PosY)
  32.         local Lines = GetLinesFromPosY(PosY)
  33.         local LinePoses = {}
  34.        
  35.         for _,Data in pairs(Lines) do
  36.             local Pos1,Pos2 = Data[1],Data[2]
  37.             local function GetRatio(Point1Y,Point2Y)
  38.                 local Point2Y,PosY = Point2Y - Point1Y,PosY - Point1Y
  39.                 return PosY/Point2Y
  40.             end
  41.             local Ratio = GetRatio(Pos1.Y.Offset,Pos2.Y.Offset)
  42.             local LerpedPos = UDim2.new(0,Lerp(Pos1.X.Offset,Pos2.X.Offset,Ratio),0,PosY)
  43.             table.insert(LinePoses,LerpedPos)
  44.         end
  45.        
  46.        
  47.        
  48.         table.sort(LinePoses,function(Pos1,Pos2) return Pos1.X.Offset < Pos2.X.Offset end)
  49.        
  50.        
  51.         for i = 1, #LinePoses/2 do
  52.             i = i*2
  53.             local Pos1,Pos2 = LinePoses[i-1],LinePoses[i]
  54.            
  55.             local Length = Pos2.X.Offset - Pos1.X.Offset
  56.             if Length > 0 then
  57.                 local Frame = Instance.new("Frame")
  58.                 Frame.Position = Pos1
  59.                 Frame.Size = UDim2.new(0,Length,0,Quality)
  60.                 Frame.BorderSizePixel = 0
  61.                 Frame.Parent = Parent
  62.             end
  63.         end
  64.     end
  65.    
  66.     local MinY,MaxY = math.huge,0
  67.    
  68.     for _,Point in pairs(Points) do
  69.         if Point.Y.Offset < MinY then
  70.             MinY = Point.Y.Offset
  71.         end
  72.         if Point.Y.Offset > MaxY then
  73.             MaxY = Point.Y.Offset
  74.         end
  75.     end
  76.     for Add = 1, (MaxY - MinY)/Quality do
  77.         DrawLine(MinY + (Quality*Add))
  78.     end
  79. end
  80.  
  81. local Point3 = UDim2.new(0,220,0,20)
  82. local Point1 = UDim2.new(0,25,0,100)
  83. local Point2 = UDim2.new(0,130,0,130)
  84. local Point4 = UDim2.new(0,200,0,260)
  85. local Point5 = UDim2.new(0,180,0,110)
  86. local Point6 = UDim2.new(0,130,0,220)
  87. local Point7 = UDim2.new(0,80,0,70)
  88. local Point8 = UDim2.new(0,90,0,160)
  89.  
  90. game.StarterGui.ScreenGui.Container:ClearAllChildren()
  91. DrawTriangle(game.StarterGui.ScreenGui.Container,{Point1,Point2,Point3,Point4,Point5,Point6,Point7,Point8})
Advertisement
Add Comment
Please, Sign In to add comment