Guest User

Roblox Fibonacci Spiral Visual

a guest
Jan 1st, 2016
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | None | 0 0
  1. local Size = 5
  2. local StartX,StartY = 325,200
  3.  
  4.  
  5. local function Fibonacci(N)
  6.     if N < 0 then error("Fibonacci infinitely recurses with a negative number") end
  7.     if N == 0 then return 0 end
  8.     if N == 1 then return 1 end
  9.     return Fibonacci(N-1) + Fibonacci(N-2)
  10. end
  11.  
  12. local ScreenGui = Instance.new("ScreenGui")
  13. ScreenGui.Name = "FibonacciSpiral"
  14. ScreenGui.Parent = game.StarterGui
  15.  
  16. local ClockwiseTurn = 1
  17.  
  18. local function DrawCurve(PosX,PosY,Fib,Rotation)
  19.     local Frame = Instance.new("ImageLabel")
  20.     Frame.Size = UDim2.new(0,Fib*Size,0,Fib*Size)
  21.     Frame.Position = UDim2.new(0,-Size*PosX + StartX,0,-Size*PosY + StartY)
  22.     Frame.BackgroundTransparency = 1
  23.     Frame.Image = "rbxassetid://338513872"
  24.     Frame.Rotation = Rotation
  25.     Frame.Parent = ScreenGui
  26. end
  27.  
  28. --Code for box placement (C#): http://stackoverflow.com/questions/18120908/fibonacci-boxes
  29. local Left,Right,Top,Bottom = 0,1,0,0
  30. for i = 1, 10 do
  31.     local Fib = Fibonacci(i)
  32.    
  33.    
  34.     if ClockwiseTurn == 1 then
  35.         DrawCurve(Right,Bottom + Fib,Fib,90)
  36.         Bottom = Bottom + Fib
  37.     elseif ClockwiseTurn == 2 then
  38.         DrawCurve(Right + Fib,Bottom,Fib,0)
  39.         Right = Right + Fib
  40.     elseif ClockwiseTurn == 3 then
  41.         DrawCurve(Right,Top,Fib,-90)
  42.         Top = Top - Fib
  43.     elseif ClockwiseTurn == 4 then
  44.         DrawCurve(Left,Bottom,Fib,-180)
  45.         Left = Left - Fib
  46.     end
  47.    
  48.     ClockwiseTurn = ClockwiseTurn + 1
  49.     if ClockwiseTurn > 4 then ClockwiseTurn = 1 end
  50. end
Add Comment
Please, Sign In to add comment