Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Joint drawing [v0.99]
- !color ff00ff => changer la couleur (mettez un code hexadecimal)
- !alpha xx => changer la transparence de ses joints (entre 0 et 1)
- !line xx => Changer l'épaisseur de ses joints
- !bezier xx => Changer le nombre de joints pour former un bezier
- ]]--
- interface = {}
- interface.joint = {}
- xml = {}
- xml.joint = {}
- editor = {}
- editor.joint = {}
- tool = {}
- function init ()
- info = {}
- for name in pairs(tfm.get.room.playerList) do eventNewPlayer(name) end
- eventNewGame()
- end
- function interface.joint.affiche (name)
- ui.addTextArea( 0, "<b>type de joint : <a href='event:joint type •'>•</a> <a href='event:joint type /'>/</a> <a href='event:joint type ~'>~</a></b>", name, 0, -30, 150, 20, 0x324650, 0x324650, 0.8, true)
- ui.addTextArea( 1, "<b>taille : "..tostring(info[name].prop.line).."</b>", name, 160, -30, 80, 20, 0x324650, 0x324650, 0.8, true)
- ui.addTextArea( 2, "<b>couleur : <font color='#"..string.format('%x', info[name].prop.color).."'>•</font></b>", name, 250, -30, 80, 20, 0x324650, 0x324650, 0.8, true)
- ui.addTextArea( 3, "<b>alpha : "..tostring(info[name].prop.alpha).."</b>", name, 340, -30, 80, 20, 0x324650, 0x324650, 0.8, true)
- ui.addTextArea( 4, "<b>bezier : "..tostring(info[name].bezier).."</b>", name, 430, -30, 80, 20, 0x324650, 0x324650, 0.8, true)
- end
- function eventNewPlayer(name)
- system.bindMouse(name, true)
- tfm.exec.bindKeyboard(name, 8, true, true)
- info[name] = {joint="/", point={}, bezier=10, prop = { color=0xffffff, alpha=0.8, line=10, foreground=true}}
- interface.joint.affiche (name)
- end
- function eventNewGame ()
- joint = {}
- tfm.exec.addPhysicObject(1, -500, -500, {['type']=1})
- end
- function eventKeyboard(name, key, down, x, y)
- if key == 8 then editor.joint.delete(#xml.joint) end
- end
- function eventChatCommand(name, command)
- if command:sub(0,5) == "color" then
- info[name].prop.color = tonumber('0x'..command:sub(7))
- ui.updateTextArea(2, "<b>couleur : <font color='#"..string.format('%x', info[name].prop.color).."'>•</font></b>", name)
- elseif command:sub(0,4) == "line" then
- info[name].prop.line = tonumber(command:sub(6))
- ui.updateTextArea(1, "<b>taille : "..tostring(info[name].prop.line).."</b>", name)
- elseif command:sub(0,5) == "alpha" then
- info[name].prop.alpha = tonumber(command:sub(7))
- ui.updateTextArea(3, "<b>alpha : "..tostring(info[name].prop.alpha).."</b>", name)
- elseif command:sub(0,6) == "bezier" then
- local n = math.abs(tonumber(command:sub(8)))
- info[name].bezier = n>0 and n or 10
- ui.updateTextArea(4, "<b>bezier : "..tostring(info[name].bezier).."</b>", name)
- end
- end
- function eventTextAreaCallback (id, name, call)
- local section = {}
- for w in string.gmatch(call, "%S+") do
- table.insert(section, w)
- end
- if section[1] == "joint" then
- if section[2] == "type" then
- info[name].joint = section[3]
- tool.reset_point(name)
- end
- end
- end
- function eventMouse (name, x, y)
- if info[name].joint == '•' then
- local prop = info[name].prop
- prop.point1 = tool.s_coord(x,y)
- prop.point2 = tool.s_coord(x+1,y)
- editor.joint.add(prop)
- tool.reset_point(name)
- elseif info[name].point[1] then
- if info[name].joint == '/' then
- local prop = info[name].prop
- prop.point1 = tool.s_coord(info[name].point[1].x, info[name].point[1].y)
- prop.point2 = tool.s_coord(x,y)
- editor.joint.add(prop)
- tool.reset_point(name)
- elseif info[name].point[2] then
- if info[name].point[3] then
- editor.joint.bezier (info[name].point[1].x, info[name].point[1].y , info[name].point[2].x, info[name].point[2].y , info[name].point[3].x, info[name].point[3].y , x,y , info[name].bezier , info[name].prop)
- tool.reset_point(name)
- else
- info[name].point[3] = {x=x, y=y}
- end
- else
- info[name].point[2] = {x=x, y=y}
- end
- else
- info[name].point[1] = {x=x, y=y}
- end
- end
- function editor.joint.add (prop)
- table.insert(xml.joint, prop)
- tfm.exec.addJoint (#xml.joint, 1, 1, prop)
- end
- function editor.joint.delete (id)
- if id ~= 0 then
- tfm.exec.removeJoint (id)
- table.remove(xml.joint, id)
- end
- end
- function editor.joint.bezier ( x1,y1 , x2,y2 , x3,y3 , x4,y4 , div, prop )
- local x = 1/div
- local xb, yb = x1,y1
- prop.point1 = tostring(xb)..','..tostring(yb)
- for i=1, div do
- xn = math.floor((1-x)^3*x1 + 3*x*(1-x)^2*x2 + 3*x^2*(1-x)*x3 +x ^3*x4)
- yn = math.floor((1-x)^3*y1 + 3*x*(1-x)^2*y2 + 3*x^2*(1-x)*y3 +x ^3*y4)
- x= x+1/div
- prop.point2 = tool.s_coord(xn,yn)
- editor.joint.add(prop)
- prop.point1 = prop.point2
- end
- end
- function tool.s_coord (x, y)
- return tostring(x)..','..tostring(y)
- end
- function tool.reset_point (name)
- info[name].point = {}
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement