Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --To use the main function: Type in console 'plot("filename.bmp")' (It is necessary that you save the file as a 24-bit bitmap), and then type in the element to be drawn with. With some elements, it will use a property other than deco layer. It also always automatically does temp and life.
- --COAL/BCOL: tmp2 - Grayscale
- --GRAV: vx - Grayscale
- --BRAY: life - Grayscale
- --EMBR: ctype - Color, but not very high-quality for very dark colors
- --WIFI: tmp - Neither color nor grayscale, no idea what to call it.
- --Any powered material: life - Grayscale
- --WWLD: Ctype - not useful for drawing images, but can transfer patterns from Golly!
- --There is a secondary function too: elemplot("filename.bmp"). It creates an image with a limited pallete of elements, but it is just in monochrome.
- function plot(filename)
- elemtype = tpt.input("Element type","This is the element it will be drawn in")
- local f=io.open(filename,'rb')
- f:seek('set',18)
- local wval=string.byte(f:read(1))+string.byte(f:read(1))*256+string.byte(f:read(1))*65536+string.byte(f:read(1))*16777216
- local hval=string.byte(f:read(1))+string.byte(f:read(1))*256+string.byte(f:read(1))*65536+string.byte(f:read(1))*16777216
- f:seek('set',54)
- local r,g,b=0,0,0
- for j=0,hval-1 do
- for i=0,wval-1 do
- b,g,r=string.byte(f:read(1)),string.byte(f:read(1)),string.byte(f:read(1))
- if i<612 and hval-j<380 and(not(r + g + b < 0)) then
- tpt.create(i,hval-j,elemtype)
- if elemtype ~= 'wwld' then
- tpt.set_property('dcolour',r*65536+g*256+b+16777216*255,i,hval-j)
- end
- if elemtype ~= 'embr' and elemtype ~= 'pump' and elemtype ~= 'lcry' and elemtype ~= 'pcln' and elemtype ~= 'hswc' and elemtype ~= 'gpmp' and elemtype ~= 'swch' and elemtype ~= 'pbcn' and elemtype ~= 'dlay' then
- tpt.set_property('life',(r+g+b) * (1000/765),i,hval-j)
- end
- if elemtype ~= 'coal' then
- tpt.set_property('temp',((r / 255) * (6150) - (g / 255) * (4270)-(b / 255)) + 273.15,i,hval-j)
- end
- if elemtype == 'grav' then
- tpt.set_property('vx',(r + g + b) * (10 / 765),i,hval-j)
- end
- if elemtype == 'bray' then
- tpt.set_property('tmp',1,i,hval-j)
- elseif elemtype == 'embr' then
- tpt.set_property('ctype',r*65536+g*256+b+16777216*255,i,hval-j)
- elseif elemtype == 'coal' or elemtype == 'bcol' then
- tpt.set_property('tmp2',(r+g+b) + 273.15,i,hval-j)
- if elemtype ~= 'bcol' then
- tpt.set_property('life',110,i,hval-j)
- end
- tpt.set_property('tmp',50,i,hval-j)
- elseif elemtype == 'wifi' then
- tpt.set_property('tmp',((r+g+b) * (99 / 765)) + 273.15,i,hval-j)
- elseif elemtype == 'pump' or elemtype == 'lcry' or elemtype == 'pcln' or elemtype == 'hswc' or elemtype == 'gpmp' or elemtype == 'swch' or elemtype == 'pbcn' or elemtype == 'dlay' then
- tpt.set_property('life',(r + g + b) / 76.5,i,hval-j)
- elseif elemtype == 'wwld' or elemtype == 'wire' then
- if b > 250 and g < 200 then
- tpt.set_property('ctype',1,i,hval-j)
- elseif r > 150 and g > 150 then
- tpt.set_property('ctype',2,i,hval-j)
- elseif r < 100 and g < 100 and b < 100 then
- tpt.set_property('type',0,i,hval-j)
- end
- end
- end
- end
- end
- for i=1,wval%4 do f:read(1) end
- end
- function elemplot(filename)
- local f=io.open(filename,'rb')
- f:seek('set',18)
- local width=string.byte(f:read(1))+string.byte(f:read(1))*256+string.byte(f:read(1))*65536+string.byte(f:read(1))*16777216
- local height=string.byte(f:read(1))+string.byte(f:read(1))*256+string.byte(f:read(1))*65536+string.byte(f:read(1))*16777216
- f:seek('set',55)
- local r,g,b=0,0,0
- for j=0,height-1 do
- for i=0,width-1 do
- b,g,r=string.byte(f:read(1)),string.byte(f:read(1)),string.byte(f:read(1))
- if i<612 and height-j<380 then
- tpt.create(i,height-j,elemtype)
- if r + g + b < 10 then
- tpt.set_property('type','bray',i,height-j)
- tpt.set_property('life',50,i,height-j)
- tpt.set_property('tmp',1,i,height-j)
- elseif r + g + b < 80 then
- tpt.set_property('type','grav',i,height-j)
- elseif r + g + b < 120 then
- tpt.set_property('type','coal',i,height-j)
- tpt.set_property('life',110,i,height-j)
- tpt.set_property('tmp',50,i,height-j)
- elseif r + g + b < 160 then
- tpt.set_property('type','bcol',i,height-j)
- tpt.set_property('life',110,i,height-j)
- elseif r + g + b < 200 then
- tpt.set_property('type','glas',i,height-j)
- elseif r + g + b < 250 then
- tpt.set_property('type','lcry',i,height-j)
- elseif r + g + b < 290 then
- tpt.set_property('type','bgla',i,height-j)
- elseif r + g + b < 380 then
- tpt.set_property('type','brck',i,height-j)
- elseif r + g + b < 430 then
- tpt.set_property('type','lcry',i,height-j)
- tpt.set_property('tmp2',6,i,height-j)
- elseif r + g + b < 490 then
- tpt.set_property('type','stne',i,height-j)
- elseif r + g + b < 560 then
- tpt.set_property('type','lcry',i,height-j)
- tpt.set_property('tmp2',10,i,height-j)
- elseif r + g + b < 580 then
- tpt.set_property('type','cnct',i,height-j)
- elseif r + g + b < 620 then
- tpt.set_property('type','rbdm',i,height-j)
- elseif r + g + b < 800 then
- tpt.set_property('type','whol',i,height-j)
- end
- end
- end
- for i=1,width%4 do f:read(1) end
- end
- end
- -- elseif r + g + b < 10 then
- -- tpt.set_property('type','bray',i,height-j)
Advertisement
Add Comment
Please, Sign In to add comment