Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- energytypes = { [18]=true, [31]=true, [136]=true, }
- validwalls = { [222]=true, [223]=true, [224]=true, [225]=true, [227]=true, [228]=true, [229]=true, [230]=true, [231]=true, [232]=true, [233]=true, [234]=true, [235]=true, [240]=true, [242]=true, [245]=true, }
- tools = { [236]=true, [237]=true, [238]=true, [239]=true, }
- setctype = { [9]=true,[74]=true,[83]=true,[85]=true,[93]=true,[153]=true,}
- function create(x,y,c,small)
- local t = c%256
- local v = math.floor(c/256)
- if t==237 or t==238 then --heat and cool!
- local temp = tpt.get_property("type",x,y)>0 and tpt.get_property("temp",x,y) or nil
- if t==237 and temp~=nil and temp<9999 then
- local heatchange = 4 --implement more temp changes later (ctrl-shift)
- tpt.set_property("temp",math.min(temp+heatchange,9999),x,y)
- elseif t==238 and temp~=nil and temp>0 then
- local heatchange = 4
- tpt.set_property("temp",math.max(temp-heatchange,0),x,y)
- end
- return
- end
- if small then --set ctype for CLNE types if smallish brush
- if not setctype[c] then
- local cm = tpt.get_property("type",x,y)
- if setctype[cm] then
- if (cm==74 or cm==153) and (c==35 or c==36) then return end --don't give PCLN ctypes of PSCN or NSCN
- tpt.set_property("ctype",c,x,y)
- return
- end
- end
- end
- if t==0 then
- tpt.delete(x,y)
- else
- local i = tpt.create(x,y,t)
- --special case for GoL creation
- if t==78 and i>=0 then tpt.set_property("ctype",v,i) tpt.set_property("tmp",GoLrule[(v+2)][10],i) end
- end
- end
- function create_line(x1,y1,x2,y2,rx,ry,c,brush) -- Taken From Powder Toy Source Code
- if c == 87 or c == 158 then return end --never do lines of FIGH and LIGH
- local cp = math.abs(y2-y1)>math.abs(x2-x1)
- local x = 0 local y = 0 local dx = 0 local dy = 0 local sy = 0 local e = 0.0 local de = 0.0 local first = true
- if cp then y = x1 x1 = y1 y1 = y y = x2 x2 = y2 y2 = y end
- if x1 > x2 then y = x1 x1 = x2 x2 = y y = y1 y1 = y2 y2 = y end
- dx = x2 - x1 dy = math.abs(y2 - y1) if dx ~= 0 then de = dy/dx end
- y = y1 if y1 < y2 then sy = 1 else sy = -1 end
- for x = x1, x2 do
- if cp then
- drawstuff(y,x,rx,ry,c,first,brush)
- else
- drawstuff(x,y,rx,ry,c,first,brush)
- end
- first = false
- e = e + de
- if e >= 0.5 then
- y = y + sy
- e = e - 1
- if y1<y2 then
- if y>y2 then return end
- elseif y<y2 then return end
- if (rx+ry)==0 or c>=222 then
- if cp then
- drawstuff(y,x,rx,ry,c,first,brush)
- else
- drawstuff(x,y,rx,ry,c,first,brush)
- end
- end
- end
- end
- end
- function create_box(x1,y1,x2,y2,c)
- local i = 0 local j = 0
- if x1>x2 then i=x2 x2=x1 x1=i end
- if y1>y2 then j=y2 y2=y1 y1=j end
- for j=y1, y2 do
- for i=x1, x2 do
- create(i,j,c)
- end
- end
- end
- function incurrentbrush(i,j,rx,ry,brush)
- if brush==0 then
- return (math.pow(i,2)*math.pow(ry,2)+math.pow(j,2)*math.pow(rx,2)<=math.pow(rx,2)*math.pow(ry,2))
- elseif brush==1 then
- return (math.abs(i)<=rx and math.abs(j)<=ry)
- elseif brush==2 then
- return ((math.abs((rx+2*i)*ry+rx*j) + math.abs(2*rx*(j-ry)) + math.abs((rx-2*i)*ry+rx*j))<=(4*rx*ry))
- else
- return false
- end
- end
- function drawstuff(x,y,rx,ry,c,fill,brush) -- Draws or erases elements
- local energycheck = energytypes[c]
- local small = (rx+ry)<=16
- if c == 87 or c == 158 then create(x,y,c) return end --only draw one pixel of FIGH and LIGH
- --walls!
- local dw = false local b = 0
- if validwalls[c] then
- dw = true
- if c~=230 then b = c-100 end
- end
- if tools[c] then fill = true end
- if dw then
- local r=math.floor(rx/4)
- local wx = math.floor(x/4)- math.floor(r/2)
- local wy = math.floor(y/4)- math.floor(r/2)
- if b==125 then
- wx = wx + math.floor(r/2)
- wy = wy + math.floor(r/2)
- for v=-1,1 do
- for u=-1,1 do
- if (wx+u>=0 and wx+u<153 and wy+v>=0 and wy+v<96 and tpt.get_wallmap(wx+u,wy+v)==125) then
- return
- end end end
- tpt.set_wallmap(wx,wy,b)
- return
- end
- tpt.set_wallmap(wx,wy,r+1,r+1,b)
- return
- end
- if rx<=0 then--0 radius loop prevention
- for j=y-ry,y+ry do
- if valid(x,j,energycheck,c) then
- create(x,j,c,small) end
- end
- return
- end
- local tempy = y local oldy = y
- if brush==2 then tempy=y+ry end
- for i = x - rx, x do
- oldy = tempy
- local check = incurrentbrush(i-x,tempy-y,rx,ry,brush)
- if check then
- while check do
- tempy = tempy - 1
- check = incurrentbrush(i-x,tempy-y,rx,ry,brush)
- end
- tempy = tempy + 1
- if fill then
- local jmax = 2*y - tempy
- if brush == 2 then jmax=y+ry end
- for j = tempy, jmax do
- if valid(i,j,energycheck,c) then
- create(i,j,c,small) end
- if i~=x and valid(x+x-i,j,energycheck,c) then
- create(x+x-i,j,c,small) end
- end
- else
- if (oldy ~= tempy and brush~=1) or i==x-rx then oldy = oldy - 1 end
- for j = tempy, oldy+1 do
- local i2=2*x-i local j2 = 2*y-j
- if brush==2 then j2=y+ry end
- if valid(i,j,energycheck,c) then
- create(i,j,c,small) end
- if i2~=i and valid(i2,j,energycheck,c) then
- create(i2,j,c,small) end
- if j2~=j and valid(i,j2,energycheck,c) then
- create(i,j2,c,small) end
- if i2~=i and j2~=j and valid(i2,j2,energycheck,c) then
- create(i2,j2,c,small) end
- end
- end
- end
- end
- end
- function valid(x,y,energycheck,c)
- if x >= 0 and x < 612 and y >= 0 and y < 384 then
- if energycheck then
- if energytypes[tpt.get_property("type",x,y)] then return false end
- end
- return true end
- end
- function floodparts(x,y,c,cm,bm)
- local x1=x local x2=x
- if cm==-1 then
- if c==0 then
- cm = tpt.get_property("type",x,y)
- if cm==0 then return false end
- else
- cm = 0
- end
- end
- --wall check here
- while x1>=4 do
- if (tpt.get_property("type",x1-1,y)~=cm) then break end
- x1 = x1-1
- end
- while x2<=608 do
- if (tpt.get_property("type",x2+1,y)~=cm) then break end
- x2 = x2+1
- end
- for x=x1, x2 do
- if c==0 then tpt.delete(x,y) end
- if c>0 and c<222 then create(x,y,c) end
- end
- if y>=5 then
- for x=x1,x2 do
- if tpt.get_property("type",x,y-1)==cm then
- if not floodparts(x,y-1,c,cm,bm) then
- return false
- end end end
- end
- if y<379 then
- for x=x1,x2 do
- if tpt.get_property("type",x,y+1)==cm then
- if not floodparts(x,y+1,c,cm,bm) then
- return false
- end end end
- end
- return true
- end
- function clearsim()
- tpt.start_getPartIndex()
- while tpt.next_getPartIndex() do
- local index = tpt.getPartIndex()
- tpt.set_property("type",0,index)
- end
- tpt.reset_velocity(0,0,153,96)
- tpt.set_pressure(0,0,153,96,0)
- tpt.set_wallmap(0,0,153,96,0)
- end
Add Comment
Please, Sign In to add comment