Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local gstatus='off'
- local timei=20
- local data=0
- local pos=1
- local time=0
- local maxdata=100
- local array = {}
- array[1]=0
- local temp=0
- local h=0
- local act=1
- array[1]=0
- array[2]=0
- local function gclear()
- for o=1, 610 do
- array[o]=0
- end
- pos=1
- maxdata=100
- end
- local function updatetimep()
- timei=timei+5
- end
- local function updatetimem()
- if time<5 then
- else
- timei=timei-5
- end
- end
- local function file_exists(name)
- local f=io.open(name,"r")
- if f~=nil then io.close(f) return 1 else return 0 end
- end
- local function image()
- if gstatus=='off' then
- return
- end
- if tpt.set_pause() == 1 then
- for i=1, tonumber(pos) do
- if i==1 then
- data2=100-(tonumber(array[i])*100)/maxdata
- data1=100-(tonumber(array[i])*100)/maxdata
- elseif i==2 then
- data2=100-(tonumber(array[i])*100)/maxdata
- data1=100-(tonumber(array[i-1])*100)/maxdata
- else
- data2=100-(tonumber(array[i-1])*100)/maxdata
- data1=100-(tonumber(array[i-2])*100)/maxdata
- end
- graphics.drawLine(i, data1, i, data2, 192, 192, 192)
- end
- graphics.drawLine(1, 101, 610, 101, 255, 9, 9)
- return
- end
- if timei~=timeold then
- time=0
- timeold=timei
- end
- data=0
- h=0
- tpt.start_getPartIndex()
- while tpt.next_getPartIndex() do
- h=h+1
- local index = tpt.getPartIndex()
- prop=tpt.get_property("temp",index)
- data=math.ceil(data+prop)-274
- end
- if h>0 then
- data=math.ceil(data/h)
- end
- time=time+1
- if time==timei then
- time=0
- if data>maxdata then
- maxdata=data+1
- end
- if data<0 then
- data=0
- else
- array[tonumber(pos)]=tonumber(data)
- pos=pos+1
- if pos==610 then
- pos=1
- maxdata=100
- end
- end
- end
- for i=1, tonumber(pos) do
- if i==1 then
- data2=100-(tonumber(array[i])*100)/maxdata
- data1=100-(tonumber(array[i])*100)/maxdata
- elseif i==2 then
- data2=100-(tonumber(array[i])*100)/maxdata
- data1=100-(tonumber(array[i-1])*100)/maxdata
- else
- data2=100-(tonumber(array[i-1])*100)/maxdata
- data1=100-(tonumber(array[i-2])*100)/maxdata
- end
- graphics.drawLine(i, data1, i, data2, 192, 192, 192)
- end
- graphics.drawLine(1, 101, 610, 101, 255, 9, 9)
- timeold=timei
- end
- tpt.register_step(image)
- local bmpfile = {}
- for a=1, 100 do
- bmpfile[a] = {}
- for b=1, 610 do
- bmpfile[a][b]='ffffff'
- end
- end
- function string.fromhex(str)
- local x = {}
- for y in str:gmatch('(..)') do
- x[#x+1] = string.char( tonumber(y, 16) )
- end
- return table.concat( x )
- end
- local function gwrite()
- --write graph to image
- bmpfile = {}
- for a=1, 100 do
- bmpfile[a] = {}
- for b=1, 610 do
- bmpfile[a][b]='FFFFFF'
- end
- bmpfile[a][611]='FFFF'
- end
- for g=1, 610 do
- if not array[g] then
- array[g]=0
- end
- if array[g]==0 then
- array[g]=1
- end
- h=math.ceil(100-(tonumber(array[g])*100)/maxdata)
- bmpfile[101-h][g]='FF008C'
- if g==1 then
- bmpfile[101-h][g]='FF008C'
- else
- h1=math.ceil(100-(tonumber(array[g])*100)/maxdata)
- h2=math.ceil(100-(tonumber(array[g-1])*100)/maxdata)
- if h1~=h2 then
- if h1>h2 then
- for k=h2, h1 do
- bmpfile[101-k][g]='FF008C'
- end
- else
- for k=h1, h2 do
- bmpfile[101-k][g]='FF008C'
- end
- end
- end
- end
- end
- local n=0
- repeat
- n=n+1
- arg='graph'..n..'.bmp'
- until file_exists(arg)==0
- local out = assert(io.open(arg, "a"))
- imagestart='424DD6CB02000000000036000000280000006202000064000000010018000000000000000000C40E0000C40E00000000000000000000'
- out:write(string.fromhex(imagestart))
- assert(out:close())
- local out = assert(io.open(arg, "a"))
- for a=1,100 do
- for b=1,611 do
- out:write(string.fromhex(tostring(bmpfile[a][b])))
- end
- end
- assert(out:close())
- end
- local function button(x,y,w,h,c,r,g,b,action)
- graphics.drawRect(x, y, w, h, r, g, b)
- k=string.len(c)*4+string.len(c)-1
- graphics.drawText(x+(w-k)/2, y+(h-7)/2, c)
- if (tpt.mousex>=x) and (tpt.mousex<=x+w) and (tpt.mousey>=y) and (tpt.mousey<=y+h) then
- graphics.fillRect(x, y, w, h, r, g, b,50)
- end
- function click(mousex, mousey, button, event)
- if (mousex>=x) and (mousex<=x+w) and (mousey>=y) and (mousey<=y+h) and (button==1) then
- if event==3 then
- graphics.fillRect(x, y, w, h, r, g, b)
- p=1
- end
- if (event==2) and (p==1) then
- p=0
- action()
- end
- end
- end
- tpt.register_mouseclick(click)
- end
- local function hud()
- if gstatus=='on' then
- button(550,3,50,12,'Clear',255,255,100,gclear)
- button(550,18,50,12,'Write',155,255,255,gwrite)
- button(550,33,12,12,'+',255,155,255,updatetimep)
- button(588,33,12,12,'-',155,155,255,updatetimem)
- graphics.drawText(570, 35, timei)
- end
- end
- tpt.register_step(hud)
- local function toggle(a,b,c,d)
- if (b==103) and (c==256) and (d==1) then
- if gstatus=='off' then
- gstatus='on'
- else
- gstatus='off'
- end
- end
- if (b==103) and (c==256) and (d==2) then
- ren.grid(0)
- end
- end
- tpt.register_keypress(toggle)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement