Advertisement
DayTimer

Langton's ant. LR.

Aug 5th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. local ANT = elements.allocate("DayLightInc", "ANT")
  2. elements.element(ANT, elements.element(elements.DEFAULT_PT_PROT))
  3. elements.property(ANT, "Name", "ANT")
  4. elements.property(ANT, "Description", "Langtons's ant. You can set speed by changing ''dcolour'' property (Default = 20). LR")
  5. elements.property(ANT, "Colour", 0xff8888)
  6. elements.property(ANT, "MenuSection", 12)
  7.  
  8. local function update (i,xu,yu,s,nt)
  9.   ctype = sim.partProperty(i, "ctype")
  10.   if ctype == 0 then
  11.     sim.partProperty(i, "life", xu);
  12.     sim.partProperty(i, "tmp2", yu);
  13.     sim.partProperty(i,"ctype",14);
  14.     dc = sim.partProperty
  15.     if dc(i,"dcolour") == 0 then dc(i, "dcolour", 20) end
  16.     sim.partProperty(i, "tmp", 3)
  17.     sim.partProperty(i, "x", 5)
  18.     sim.partProperty(i, "y", 5)
  19.   else
  20.  
  21.   for ir = 1,sim.partProperty(i,"dcolour"),1 do
  22.   oldX = sim.partProperty(i, "life") -- get x
  23.   oldY = sim.partProperty(i, "tmp2") -- get y
  24.  
  25.   side = sim.partProperty(i,"tmp")
  26.   sim.partProperty(i, "x", 5)
  27.   sim.partProperty(i, "y", 5)
  28.  
  29.   idr = sim.partCreate(-1,oldX,oldY, tpt.el[dmnd])
  30.   if idr == -1 then
  31.     id = sim.partID(oldX,oldY)
  32.   else
  33.     id = nil
  34.     sim.partKill(idr)
  35.   end
  36.  
  37.   if id == nil then
  38.       side = (side+1)%4
  39.       sim.partCreate(-3,oldX,oldY,14) --if empty
  40.   else
  41.       side = (side-1)%4
  42.       sim.partKill(id) --if not empty
  43.   end
  44.  
  45.   if side == 0 then --up
  46.       oldY = oldY - 1
  47.       elseif side == 1 then --right
  48.           oldX = oldX+1
  49.           elseif side == 2 then --down
  50.               oldY = oldY+1
  51.               elseif side == 3 then --left
  52.               oldX = oldX-1
  53.   end
  54.  
  55.  
  56.   sim.partProperty(i, "life", oldX)
  57.   sim.partProperty(i,"tmp2", oldY) --return particle
  58.   sim.partProperty(i, "tmp", side)
  59.   end
  60.   end
  61. end
  62. elements.property(ANT, "Update", update)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement