Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- math.randomseed(os.time())
- local function toCart(r, a)
- return {x = math.cos(a)*r, y = math.sin(a)*r}
- end
- local function s(text)
- return "_{"..text.."}"
- end
- local function line(x1,y1,x2,y2)
- local L = "\\left"
- local R = "\\right"
- local out = ""
- local init = "(t("..(x2-x1)..")+"..x1..",t("..(y2-y1)..")+"..y1..")"
- for i = 1, #init do
- local c = init:sub(i,i)
- if c == "(" or c == "{" or c == "[" then
- out = out..L..c
- elseif c == ")" or c == "}" or c == "]" then
- out = out..R..c
- else
- out = out..c
- end
- end
- return out
- end
- local movers = {}
- for i = 1, 5 do
- local b = {}
- b.Vel = toCart(1, math.random(0, 360)*math.pi/180)
- b.Bounds = {xmin = -5, xmax = 5, ymin = -5, ymax = 5}
- b.Pos = {x = 0, y = 0}
- table.insert(movers, b)
- end
- local out = "I\\left(a,s,l\\right)=a\\left[s,...s+l\\right]\n"
- out = out.."p=\\left["
- local keyframes = 100
- local subframes = 5
- local frames = {}
- for m, mover in ipairs(movers) do
- local frame = {}
- for f = 1, keyframes do
- for s = 1, subframes do
- local AA = "\\left("..mover.Pos.x..","..mover.Pos.y.."\\right)"
- table.insert(frame, AA)
- mover.Pos.x = mover.Pos.x + mover.Vel.x/subframes
- mover.Pos.y = mover.Pos.y + mover.Vel.y/subframes
- if mover.Pos.x > mover.Bounds.xmax then
- mover.Pos.x = mover.Bounds.xmax
- mover.Vel.x = mover.Vel.x * -1
- end
- if mover.Pos.x < mover.Bounds.xmin then
- mover.Pos.x = mover.Bounds.xmin
- mover.Vel.x = mover.Vel.x * -1
- end
- if mover.Pos.y > mover.Bounds.ymax then
- mover.Pos.y = mover.Bounds.ymax
- mover.Vel.y = mover.Vel.y * -1
- end
- if mover.Pos.y < mover.Bounds.ymin then
- mover.Pos.y = mover.Bounds.ymin
- mover.Vel.y = mover.Vel.y * -1
- end
- end
- end
- table.insert(frames, frame)
- end
- local i = 1
- while i < keyframes*subframes do
- for p, f in ipairs(frames) do
- -- for i, s in ipairs(f) do
- out = out..f[i]
- -- if p ~= #frames then
- -- out = out..","
- -- end
- if i < keyframes*subframes-1 or p ~= #frames then
- out = out..","
- end
- -- end
- end
- i = i+1
- end
- out = out.."\\right]\n"
- out = out.."I\\left(p,T,"..(#movers-1).."\\right)\n"
- out = out.."T=0"
- print(out)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement