Advertisement
ERROR_CODE

2D Animator

Nov 6th, 2024 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. local ScreenGui = Instance.new("ScreenGui")
  2. local Frame = Instance.new("Frame")
  3. local DrawingArea = Instance.new("Frame")
  4.  
  5. ScreenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
  6.  
  7. Frame.Parent = ScreenGui
  8. Frame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  9. Frame.Size = UDim2.new(0.8, 0, 0.8, 0) -- Уменьшенный размер
  10. Frame.Position = UDim2.new(0.1, 0, 0.1, 0) -- Центрирование
  11.  
  12. DrawingArea.Parent = Frame
  13. DrawingArea.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  14. DrawingArea.Size = UDim2.new(1, 0, 1, 0)
  15.  
  16. local drawing = false
  17. local lastPosition = nil
  18.  
  19. local function startDrawing(input)
  20.     drawing = true
  21.     lastPosition = input.Position
  22. end
  23.  
  24. local function stopDrawing()
  25.     drawing = false
  26.     lastPosition = nil
  27. end
  28.  
  29. local function draw(input)
  30.     if drawing and lastPosition then
  31.         local currentPosition = input.Position
  32.         local line = Instance.new("Frame")
  33.         line.Parent = DrawingArea
  34.         line.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
  35.         line.BorderSizePixel = 0
  36.         line.Size = UDim2.new(0, (currentPosition - lastPosition).magnitude, 0, 4) -- Толщина линии увеличена
  37.         line.Position = UDim2.new(0, lastPosition.X, 0, lastPosition.Y)
  38.         line.Rotation = math.deg(math.atan2(currentPosition.Y - lastPosition.Y, currentPosition.X - lastPosition.X))
  39.         lastPosition = currentPosition
  40.     end
  41. end
  42.  
  43. DrawingArea.InputBegan:Connect(function(input)
  44.     if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  45.         startDrawing(input)
  46.     end
  47. end)
  48.  
  49. DrawingArea.InputEnded:Connect(function(input)
  50.     if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  51.         stopDrawing()
  52.     end
  53. end)
  54.  
  55. DrawingArea.InputChanged:Connect(function(input)
  56.     if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
  57.         draw(input)
  58.     end
  59. end)
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement