Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Points = {}
- function GetDistance(P1,P2)
- return math.sqrt((P1.X-P2.X)^2 + (P1.Y-P2.Y)^2)
- end
- Links = {}
- Mouse = game.Players.LocalPlayer:GetMouse()
- function Point(UD1,UD2)
- local X=UD1.X-UD2.X
- local Y=UD1.Y-UD2.Y
- local Hyp=math.sqrt(X^2+Y^2)
- local AS=math.atan2(Y,X)
- return AS
- end
- function NewLink(Point1,Point2,Dis,Stiffness)
- if Point1 and Point2 then else return end
- local B = {}
- B.Dis = Dis or 50
- B.Stiffness = Stiffness or 0.5
- B.P1 = Point1
- B.P2 = Point2
- function B:Update()
- local P = B.P1.Position
- local P2 = B.P2.Position
- local PT1 = Point(P2,P)
- local PT2 = Point(P,P2)
- local Off1 = Vector2.new(math.cos(PT1),math.sin(PT1))
- local Off2 = Vector2.new(math.cos(PT2),math.sin(PT2))
- local Dis = GetDistance(P,P2)
- if not B.P2.Locked then
- B.P2.Position = B.P2.Position -((Off1*(Dis-B.Dis))*B.Stiffness)
- B.P2.Velocity = B.P2.Velocity -(B.P2.LastPos-B.P2.Position)
- B.P2.LastPos = B.P2.Position
- B.P2.Velocity = B.P2.Velocity*0.95
- end
- if not B.P1.Locked then
- B.P1.Position = B.P1.Position -((Off2*(Dis-B.Dis))*B.Stiffness)
- B.P1.Velocity = B.P1.Velocity -(B.P1.LastPos-B.P1.Position)
- B.P1.LastPos = B.P1.Position
- B.P1.Velocity = B.P1.Velocity*0.95
- end
- end
- table.insert(Links,B)
- end
- function MakePoint(Pos,Parent,Mass)
- local A = {}
- A.Position = Pos ~= nil and Pos or Vector2.new(0,0)
- A.Velocity = Vector2.new(0,0)
- A.Locked = false
- A.Dragging = false
- A.Draggable = true
- A.UI = Instance.new("TextButton",Parent)
- A.UI.Text = #Points+1
- A.UI.Size = UDim2.new(0,10,0,10)
- A.LastPos = A.Position
- A.Mass = Mass or 10
- function A:Update()
- if A.Dragging then
- A.Position = Vector2.new(Mouse.X,Mouse.Y)
- end
- if not A.Locked then
- local Z = Parent.AbsoluteSize
- A.Position = A.Position + A.Velocity
- if (A.Position.Y-10) < Z.Y then
- --print("Drop")
- A.Velocity = Vector2.new(0,A.Mass)
- else
- --print("Bounce")
- A.Position = Vector2.new(A.Position.X,Z.Y-10)
- A.Velocity = Vector2.new(A.Velocity.X,-A.Velocity.Y*0.5)
- end
- --A.Velocity = A.Velocity -(A.LastPos-A.Position)
- end
- --A.UI.Position = UDim2.new(0,A.Position.X,0,A.Position.Y)
- end
- A.UI.MouseButton1Down:connect(function()
- if A.Draggable then
- A.Dragging = true
- end
- end)
- A.UI.MouseButton1Up:connect(function()
- A.Dragging = false
- end)
- table.insert(Points,A)
- return A
- end
- local B = Instance.new("ScreenGui",game.Players.LocalPlayer:WaitForChild("PlayerGui"))
- SS = 8
- SizePerPixel = 50
- StartPos = Vector2.new(300,50)
- for y = 0,SS-1 do
- for x = 0,SS-1 do
- local S = MakePoint(StartPos+Vector2.new(x*SizePerPixel,y*SizePerPixel),B,10)
- if x ~= 0 then
- NewLink(S,Points[#Points-1],SizePerPixel)
- end
- if y ~= 0 then
- NewLink(S,Points[(#Points- SS)],SizePerPixel)
- end
- if y == 0 then
- S.Locked = true
- end
- end
- end
- --[[for i = 1,10 do
- local S = MakePoint(Vector2.new(B.AbsoluteSize.X/2,50*i),B)
- if i > 1 then
- NewLink(S,Points[i-1],20,0.5)
- end
- if i == 1 then
- S.Locked = true
- end
- end]]
- --[[local A = MakePoint(Vector2.new(500,500),B)
- A.Locked = true
- local C = MakePoint(Vector2.new(500,600),B)
- C:AddLink(A,100,1)
- ]]
- --[[local X1,X2,X3 = MakePoint(Vector2.new(400,50),B),MakePoint(Vector2.new(500,50),B),MakePoint(Vector2.new(600,50),B)
- X1.Locked,X2.Locked,X3.Locked = true,true,true
- local Y1,Y2,Y3 = MakePoint(Vector2.new(400,150),B),MakePoint(Vector2.new(500,150),B),MakePoint(Vector2.new(600,150),B)
- local Y4,Y5,Y6 = MakePoint(Vector2.new(400,250),B),MakePoint(Vector2.new(500,250),B),MakePoint(Vector2.new(600,250),B)
- NewLink(X1,Y1,100)NewLink(X2,Y2,100)NewLink(X3,Y3,100)
- NewLink(Y1,Y4,100)NewLink(Y2,Y5,100)NewLink(Y3,Y6,100)
- NewLink(Y1,Y2,100)NewLink(Y2,Y3,100)
- NewLink(Y4,Y5,100)NewLink(Y5,Y6,100)]]
- --[[local A = MakePoint(Vector2.new(500,500),B)
- A.Locked = true
- local C = MakePoint(Vector2.new(500,600),B)
- NewLink(A,C,100,1)]]
- Mouse.Button1Up:connect(function()
- for i,v in pairs(Points) do
- v.Dragging = false
- end
- end)
- game:GetService("RunService").RenderStepped:connect(function()
- --print("P:",C.Position,' ',' V:',C.Velocity)
- for i,v in pairs(Points) do
- v:Update()
- end
- for i,v in pairs(Links) do
- v:Update()
- end
- for i,v in pairs(Points) do
- v.UI.Position = UDim2.new(0,v.Position.X,0,v.Position.Y)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement