Advertisement
Mangus875

Desmos dot thing idk

Apr 13th, 2023 (edited)
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1. math.randomseed(os.time())
  2.  
  3. local function toCart(r, a)
  4.     return {x = math.cos(a)*r, y = math.sin(a)*r}
  5. end
  6.  
  7. local function s(text)
  8.     return "_{"..text.."}"
  9. end
  10.  
  11. local function line(x1,y1,x2,y2)
  12.     local L = "\\left"
  13.     local R = "\\right"
  14.    
  15.     local out = ""
  16.     local init = "(t("..(x2-x1)..")+"..x1..",t("..(y2-y1)..")+"..y1..")"
  17.    
  18.     for i = 1, #init do
  19.         local c = init:sub(i,i)
  20.         if c == "(" or c == "{" or c == "[" then
  21.             out = out..L..c
  22.         elseif c == ")" or c == "}" or c == "]" then
  23.             out = out..R..c
  24.         else
  25.             out = out..c
  26.         end
  27.     end
  28.    
  29.     return out
  30. end
  31.  
  32. local movers = {}
  33. for i = 1, 5 do
  34.     local b = {}
  35.     b.Vel = toCart(1, math.random(0, 360)*math.pi/180)
  36.     b.Bounds = {xmin = -5, xmax = 5, ymin = -5, ymax = 5}
  37.     b.Pos = {x = 0, y = 0}
  38.     table.insert(movers, b)
  39. end
  40.  
  41. local out = "I\\left(a,s,l\\right)=a\\left[s,...s+l\\right]\n"
  42. out = out.."p=\\left["
  43. local keyframes = 100
  44. local subframes = 5
  45. local frames = {}
  46.  
  47. for m, mover in ipairs(movers) do
  48.     local frame = {}
  49.     for f = 1, keyframes do
  50.         for s = 1, subframes do
  51.             local AA = "\\left("..mover.Pos.x..","..mover.Pos.y.."\\right)"
  52.             table.insert(frame, AA)
  53.             mover.Pos.x = mover.Pos.x + mover.Vel.x/subframes
  54.             mover.Pos.y = mover.Pos.y + mover.Vel.y/subframes
  55.            
  56.             if mover.Pos.x > mover.Bounds.xmax then
  57.                 mover.Pos.x = mover.Bounds.xmax
  58.                 mover.Vel.x = mover.Vel.x * -1
  59.             end
  60.             if mover.Pos.x < mover.Bounds.xmin then
  61.                 mover.Pos.x = mover.Bounds.xmin
  62.                 mover.Vel.x = mover.Vel.x * -1
  63.             end
  64.             if mover.Pos.y > mover.Bounds.ymax then
  65.                 mover.Pos.y = mover.Bounds.ymax
  66.                 mover.Vel.y = mover.Vel.y * -1
  67.             end
  68.             if mover.Pos.y < mover.Bounds.ymin then
  69.                 mover.Pos.y = mover.Bounds.ymin
  70.                 mover.Vel.y = mover.Vel.y * -1
  71.             end
  72.         end
  73.     end
  74.     table.insert(frames, frame)
  75. end
  76.  
  77. local i = 1
  78. while i < keyframes*subframes do
  79.   for p, f in ipairs(frames) do
  80.     -- for i, s in ipairs(f) do
  81.         out = out..f[i]
  82.  
  83.         -- if p ~= #frames then
  84.         --  out = out..","
  85.         -- end
  86.     if i < keyframes*subframes-1 or p ~= #frames then
  87.       out = out..","
  88.     end
  89.     -- end
  90.   end
  91.   i = i+1
  92. end
  93.  
  94. out = out.."\\right]\n"
  95. out = out.."I\\left(p,T,"..(#movers-1).."\\right)\n"
  96. out = out.."T=0"
  97.  
  98. print(out)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement