Advertisement
DayTimer

Langton's ant. LRRL. Symmetrical.

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