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DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDÈ-- title: Margosand -- author: visy -- desc: falling sand simulator using Margolus neighborhood rules -- script: lua local margodef = { 0,0,0,0, 1,0,0,0, 0,1,0,0, 1,1,0,0, 0,0,1,0, 1,0,1,0, 0,1,1,0, 1,1,1,0, 0,0,0,1, 1,0,0,1, 0,1,0,1, 1,1,0,1, 0,0,1,1, 1,0,1,1, 0,1,1,1, 1,1,1,1 } local sandrule = { 0,4,8,12,4,12,12,13,8,12,12,14,12,13,14,15 } local margoframe = 0 sc = 4 cls(0) buf = {} for y = 1, 137 do buf[y] = {} for x = 1, 241 do buf[y][x] = 0 end end function clearbuf() for x = 1, 240 do for y = 1, 137 do buf[y][x] = 0 end end end function findrule(r1,r2,r3,r4) for i = 0, 16 do local rr1 = margodef[(i*4)+1] local rr2 = margodef[(i*4)+2] local rr3 = margodef[(i*4)+3] local rr4 = margodef[(i*4)+4] if (r1 == rr1 and r2 == rr2 and r3 == rr3 and r4 == rr4) then return i end end return -1 end function bpix(x,y,c) buf[y+1][x+1] = c end function TIC() clearbuf() mx,my,left = mouse() if (left) then pix(mx,my,sc) end for y = -margoframe%2, 135,2 do for x = margoframe%2, 239,2 do local r1 = 0 local r2 = 0 local r3 = 0 local r4 = 0 local p1 = pix(x,y) == sc local p2 = pix(x+1,y) == sc local p3 = pix(x,y+1) == sc local p4 = pix(x+1,y+1) == sc if p1 then r1 = 1 end if p2 then r2 = 1 end if p3 then r3 = 1 end if p4 then r4 = 1 end local rule = findrule(r1,r2,r3,r4) if (rule > -1) then local transrule = sandrule[rule+1] local rp1 = margodef[(transrule*4)+1] local rp2 = margodef[(transrule*4)+2] local rp3 = margodef[(transrule*4)+3] local rp4 = margodef[(transrule*4)+4] if (rp1 == 1) then bpix(x,y,sc) end if (rp2 == 1) then bpix(x+1,y,sc) end if (rp3 == 1) then bpix(x,y+1,sc) end if (rp4 == 1) then bpix(x+1,y+1,sc) end end end end cls(0) for y = 0, 135 do for x = 0, 239 do pix(x,y,buf[y+1][x+1]) end end line(0,135,240,135,sc) margoframe = margoframe + 1 end