Advertisement
DayTimer

Langton's ant. LRL.

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