Advertisement
Hachem16

Snowflake-shaped maker

Dec 26th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.51 KB | None | 0 0
  1. admin = "Legojumper"
  2. seed = math.random(0,555)..math.random(555,962) math.randomseed(seed)
  3. line = math.random(5,7)
  4. colour = 0xAEEEEE
  5. alpha = 100   /100
  6. ang_add_by = math.random(-25,25)
  7. steps_num = math.random(7, 16)
  8. branching = math.random(2,5)
  9. foreground = true
  10. side_num = 6
  11. len_min, len_max = 20,40
  12.  
  13.  
  14. map = "@6429343"
  15.  
  16. tfm.exec.disableAutoNewGame(true)
  17. tfm.exec.disableAutoShaman(true)
  18. tfm.exec.disableAfkDeath(true)
  19.  
  20. local jn0make = tfm.exec.addJoint
  21. local id = 0
  22. local ____ld = 0
  23. function tfm.exec.addJoint(_id, g1, g2, jo0nt)
  24.     if id>=1200 then
  25.         ____ld = ____ld + 1
  26.         tfm.exec.removeJoint(____ld)
  27.     end
  28.     if _id then
  29.         jn0make(_id, g1, g2, jo0nt)
  30.     else
  31.         id = id + 1
  32.         jn0make(id, g1, g2, jo0nt)
  33.     end
  34. end
  35.  
  36. local draws = {}
  37. local _step = 1
  38. local ang = 0
  39. local to_branch = nil
  40. function eventNewGame()
  41.     tfm.exec.addPhysicObject(1, -400, -200, {type=14,dynamic = false, miceCollision=false, groundCollision=false})
  42. end
  43. eventNewGame()
  44. function draw(step, x, y, angl)
  45.     local tbb = {-1,1}
  46.     local neg_pos = tbb[math.random(1,2)]
  47.     local angl = angl and angl* neg_pos or 0
  48.     local sides = side_num
  49.     if not draws[step-1] then
  50.         draws[step] = {}
  51.         local r = math.random(len_min,len_max)
  52.         for i=1,sides do
  53.             local ang = math.rad(i * 360/sides) + math.rad(angl)
  54.             local xl = math.ceil(x + r*math.cos(ang))
  55.             local yl = math.ceil(y + r*math.sin(ang))
  56.             local p1 = x..","..y
  57.             local p2 = xl..","..yl
  58.             tfm.exec.addJoint(nil, 1,1, {type=0, point1=p1, point2=p2, line=line, color = colour, alpha=alpha, foreground=foreground})
  59.             draws[step][i] = {x=xl, y=yl}
  60.         end
  61.         local l = math.random(0,4)
  62.         to_branch = l==1 and branching or nil
  63.     else
  64.         local r = math.random(len_min,len_max)
  65.         colour = colour + math.random(-5, 5)
  66.         draws[step] = {}
  67.         for i=1,sides do
  68.             if draws[step-1][1].branched == true then
  69.                 draws[step][i] = {branched = true, branches = {}}
  70.                 for l,v in ipairs(draws[step-1][i].branches) do
  71.                     local ang = math.rad(i * 360/sides) + math.rad(angl)
  72.                     local xl = math.ceil(r*math.cos(ang) + v.x)
  73.                     local yl = math.ceil(r*math.sin(ang) + v.y)
  74.                     local p1 = v.x..","..v.y
  75.                     local p2 = xl..","..yl
  76.                     tfm.exec.addJoint(nil, 1,1, {type=0, point1=p1, point2=p2, line=line, color = colour, alpha=alpha, foreground=foreground})
  77.                     draws[step][i].branches[l] = {x=xl, y=yl}
  78.                 end
  79.             else
  80.                 if to_branch then
  81.                     draws[step][i] = {branched = true, branches = {}}
  82.                     local p_ang = 0
  83.                     for l=1,to_branch do
  84.                         local tbl = draws[step-1][i]
  85.                         local ang = math.rad(i * 360/sides) + math.rad(angl) + math.rad(p_ang)
  86.                         local xl = math.ceil(r*math.cos(ang) + tbl.x)
  87.                         local yl = math.ceil(r*math.sin(ang) + tbl.y)
  88.                         local p1 = tbl.x..","..tbl.y
  89.                         local p2 = xl..","..yl
  90.                         tfm.exec.addJoint(nil, 1,1, {type=0, point1=p1, point2=p2, line=line, color = colour, alpha=alpha, foreground=foreground})
  91.                         draws[step][i].branches[l] = {x=xl, y=yl}
  92.                         p_ang = p_ang + 20*neg_pos
  93.                     end
  94.                 else
  95.                     local tbl = draws[step-1][i]
  96.                     local ang = math.rad(i * 360/sides) + math.rad(angl)
  97.                     local xl = math.ceil(r*math.cos(ang) + tbl.x)
  98.                     local yl = math.ceil(r*math.sin(ang) + tbl.y)
  99.                     local p1 = tbl.x..","..tbl.y
  100.                     local p2 = xl..","..yl
  101.                     tfm.exec.addJoint(nil, 1,1, {type=0, point1=p1, point2=p2, line=line, color = colour, alpha=alpha, foreground=foreground})
  102.                     draws[step][i] = {x=xl, y=yl}
  103.                 end
  104.             end
  105.         end
  106.         if not to_branch then
  107.             local l = math.random(0,4)
  108.             to_branch = l==1 and branching or nil
  109.         end
  110.     end
  111.     local ran = math.random(-1,1)
  112.     line = line + ran > 0 and line+ran or line+1
  113. end
  114. function reset(seeed, branche_)
  115.     math.randomseed(seeed)
  116.     line = math.random(5,7)
  117.     colour = colour
  118.     alpha = aplha or 100/100
  119.     ang_add_by = math.random(-25,25)
  120.     steps_num = math.random(7, 16)
  121.     branching = branche_ or math.random(2,5)
  122.     foreground = true
  123.     side_num = side_num or 6
  124.     len_min, len_max = len_min or 20,len_max or 40
  125. end
  126. function eventChatCommand(name, cmd)
  127.     local args = {}
  128.     for arg in cmd:gmatch("%S+") do
  129.         args[#args+1] = arg
  130.     end
  131.     if name ~= admin then return end
  132.     if args[1] == "new" then
  133.         ang = 0
  134.         _step = 0
  135.         seed = math.random(math.random(1,300), math.random(300,400))..math.random(math.random(0,500), math.random(0,900))
  136.         reset(seed)
  137.         for i = 1,id do
  138.             tfm.exec.removeJoint(i)
  139.         end
  140.         id = 0
  141.         stop = false
  142.     elseif args[1] == "redraw" then
  143.         reset(seed)
  144.         ang = 0
  145.         _step = 0
  146.         for i = 1,id do
  147.             tfm.exec.removeJoint(i)
  148.         end
  149.         id = 0
  150.         stop = false
  151.     elseif args[1] == "set" and _step>steps_num then
  152.         if args[2] == "branching" then
  153.             if tonumber(args[3]) then
  154.                 branching = tonumber(args[3])
  155.             end
  156.         elseif args[2] == "colour" or args[2] == "color" then
  157.             ui.showColorPicker(1, name, colour, "Choose a color !")
  158.         elseif args[2] == "sides" then
  159.             if tonumber(args[3]) then
  160.                 side_num = tonumber(args[3])
  161.             end
  162.         elseif args[2] == "seed" then
  163.             if tonumber(args[3]) then
  164.                 seed = tonumber(args[3])
  165.                 reset(seed)
  166.             end
  167.         end
  168.     elseif args[1] == "get" then
  169.         if args[2] == "seed" then
  170.             ui.addTextArea(0, "<J>Seed is : <N>"..seed, nil, nil, nil, nil, nil, nil, nil, nil, true)
  171.             print(seed)
  172.         end
  173.     end
  174. end
  175. function eventColorPicked(id ,name , color)
  176.     colour = color
  177. end
  178. x = 500
  179. y = 300
  180. function eventLoop(tr, rt)
  181.     if stop then
  182.         return
  183.     elseif _step > steps_num then
  184.         stop = true
  185.         return
  186.     else
  187.         draw(_step, x, y, ang)
  188.         ang = ang + ang_add_by
  189.         _step = _step + 1
  190.     end
  191. end
  192.  
  193. for i = 1,300 do
  194.     tfm.exec.removeJoint(i)
  195. end
  196. tfm.exec.newGame(map)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement