maxkhl

Stormworks Cock Pit Code

Oct 21st, 2021 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.23 KB | None | 0 0
  1. function dial(name, value, vmin, vmax, size)
  2.     local t = {}
  3.     t.name,t.value,t.vmin,t.vmax,t.size = name,value,vmin,vmax, size
  4.     t.lX,t.lY,t.lW,t.lH = 0,0,0,0
  5.     t.showValue = false
  6.     function t.draw(x,y)
  7.         if(t.size == nil or t.size == 0) then t.size = 5 end
  8.        
  9.         cSize = t.size
  10.        
  11.         screen.setColor(15,15,15,255)
  12.         screen.drawCircleF(x+cSize,y+cSize,cSize)
  13.         screen.setColor(200,200,200,255)
  14.         screen.drawCircle(x+cSize,y+cSize,cSize)
  15.        
  16.         grVmax = vmax - vmin
  17.         norValue = t.value / grVmax
  18.         angle = norValue * math.pi * 2 - math.pi/2
  19.        
  20.         screen.setColor(255,150,0,255)
  21.         screen.drawLine(x+cSize, y+cSize, x+cSize+ math.cos(angle) * cSize,y+cSize + math.sin(angle) * cSize)
  22.        
  23.         if(t.name ~= nil and t.name ~= "") then
  24.             if(t.showValue == true) then
  25.                 textWidth = string.len(t.value) * 4
  26.                 screen.setColor(0,0,0,255)
  27.                 screen.drawRectF(x + (cSize - textWidth/2) - 1,y+cSize-1, textWidth, 7)
  28.                 screen.setColor(200,200,200,255)
  29.                 screen.drawText(x + (cSize - textWidth/2) - 1,y+cSize,t.value)
  30.             end
  31.             textWidth = string.len(t.name) * 4
  32.             screen.drawText(x + (cSize - textWidth/2) - 1,y+cSize*2,t.name)
  33.         end
  34.        
  35.         t.lX, t.lY, t.lW, t.lH = x, y, cSize*2, cSize*2+5
  36.     end
  37.     return t
  38. end
  39. function artHorizon(colorR, colorG, colorB, colorA, brightness)
  40.     local t = {}
  41.     t.color = {}
  42.     t.color.r, t.color.g, t.color.b, t.color.a = colorR, colorG, colorB, colorA
  43.     t.brightness = brightness
  44.     t.rValue = 0
  45.     t.pValue = 0
  46.     function t.draw(x,y)
  47.         --dX = math.cos(radValue)+0.5
  48.         --dY = math.sin(radValue)+0.5
  49.         --radValue = t.rValue * (math.pi * 2)
  50.         --rX = math.cos(radValue)
  51.         --rY = math.sin(radValue)
  52.         --screen.drawLine(screen.getWidth()/2, screen.getHeight()/2, screen.getWidth()/2 + rX * 10, screen.getHeight()/2 + rY*10)
  53.         --screen.drawText(0, 0, radValue * (180 / math.pi))
  54.        
  55.         dY = t.rValue / 0.5
  56.         if(dY < 0) then dYi = dY*-1 else dYi = dY end
  57.         --dYi = math.sin(dYi*(math.pi*2))
  58.            
  59.         pY = t.pValue / 0.5 + 1
  60.        
  61.         x1 = screen.getWidth()/4
  62.         y1 = (screen.getHeight()/2)*pY+(screen.getHeight()/2)*((dY*-1)/2)
  63.         x2 = screen.getWidth()/4*3
  64.         y2 = (screen.getHeight()/2)*pY+(screen.getHeight()/2)*dY/2
  65.        
  66.         y1s = (screen.getHeight()/2)*pY+(screen.getHeight()/2)*(((dY/2)*-1)/2)
  67.         y2s = (screen.getHeight()/2)*pY+(screen.getHeight()/2)*(dY/2)/2
  68.        
  69.         --x1 = screen.getWidth()/4+(5*rX)
  70.         --y1 = (screen.getHeight()/2)*pY+(10*rY*-1)
  71.         --x2 = screen.getWidth()/4*3-(5*rX-1)
  72.         --y2 = (screen.getHeight()/2)*pY+(10*rY)
  73.        
  74.         --screen.setColor(209, 95, 43, 100)
  75.         --screen.drawTriangleF(x1, y1, x2, y2, 0, screen.getHeight())
  76.         --screen.drawTriangleF(0, screen.getHeight(), x2, y2, screen.getWidth(), screen.getHeight())
  77.        
  78.         --screen.setColor(63, 137, 200, 100)
  79.         --screen.drawTriangleF(x1, y1, x2, y2, 0, 0)
  80.         --screen.drawTriangleF(0, 0, x2, y2, screen.getWidth(), 0)
  81.         screen.setColor(t.color.r*t.brightness/2, t.color.g*t.brightness/2, t.color.b*t.brightness/2, t.color.a/t.brightness/2)
  82.         if(t.brightness == 0) then return end
  83.         screen.drawLine(screen.getWidth()/4, screen.getHeight()/2, screen.getWidth()/4*2, screen.getHeight()/2-3)
  84.         screen.drawLine(screen.getWidth()/4, screen.getHeight()/2, screen.getWidth()/4*2, screen.getHeight()/2+3)
  85.         screen.drawLine(screen.getWidth()/4*3, screen.getHeight()/2, screen.getWidth()/4*2, screen.getHeight()/2-3)
  86.         screen.drawLine(screen.getWidth()/4*3, screen.getHeight()/2, screen.getWidth()/4*2, screen.getHeight()/2+3)
  87.         screen.drawCircle(screen.getWidth()/2, (screen.getHeight()/2), 3)
  88.         small = false
  89.         numLines = 20
  90.         for i=0,numLines do
  91.             a = (i-(numLines/2))/(numLines/2)
  92.             if(a < 0) then a = a*-1 end
  93.             a = (a-1)*-1
  94.             a = a*t.brightness+0.1
  95.            
  96.             screen.setColor(t.color.r * a, t.color.g * a, t.color.b * a, t.color.a * a)
  97.            
  98.             y1lp = y1-(i-(numLines/2))/numLines*130
  99.             y2lp = y2-(i-(numLines/2))/numLines*130
  100.             y1lps = y1s-(i-(numLines/2))/numLines*130
  101.             y2lps = y2s-(i-(numLines/2))/numLines*130
  102.            
  103.             if(numLines/2 == i) then
  104.                 screen.drawCircle(screen.getWidth()/2, (screen.getHeight()/2)*pY-(i-(numLines/2))/numLines*130, 2)
  105.                 screen.drawLine(
  106.                     screen.getWidth()/2,
  107.                     (screen.getHeight()/2)*pY-(i-(numLines/2))/numLines*130-2,
  108.                     screen.getWidth()/2,
  109.                     (screen.getHeight()/2)*pY-(i-(numLines/2))/numLines*130+2)
  110.             end
  111.            
  112.             if(small) then
  113.                 screen.drawLine(x1+x1/2, y1lps, x2-(screen.getWidth()-x2)/2, y2lps)
  114.             else
  115.                 screen.drawLine(x1, y1lp, x2, y2lp)
  116.             end
  117.            
  118.             small = not small
  119.         end
  120.     end
  121.     return t   
  122. end
  123.  
  124. function isInRect(x,y,w,h,px,py)
  125. return px>=x and px<=x+w and py>=y and py<=y+h
  126. end
  127.  
  128. dial1 = dial("Vel", 0.5, 0, 1, 10)
  129. dial2 = dial("Alt", 0.5, 0, 1, 10)
  130. artHorizon1 = artHorizon(0,255,0,255,1)
  131.  
  132. autopilotOn = false
  133. function onTick()
  134.     -- your code
  135.     dial1.value = input.getNumber(7)
  136.     dial1.vmax = input.getNumber(8)
  137.     dial2.value = input.getNumber(9)
  138.     dial1.vmax = input.getNumber(10)
  139.     artHorizon1.rValue = input.getNumber(11)
  140.     artHorizon1.pValue = input.getNumber(12)
  141.     artHorizon1.brightness = input.getNumber(13)
  142.     autopilotOn = input.getBool(3)
  143. end
  144.  
  145. function onDraw()
  146.     -- your code
  147.     screen.setColor(200,0,0,255)
  148.     artHorizon1.draw(0,0)
  149.     dial1.draw(0,screen.getHeight()-dial1.size*2-5)
  150.     dial2.draw(screen.getWidth()-dial2.size*2,screen.getHeight()-dial2.size*2-5)
  151.     artHorizon1.draw(0,0)
  152.     if(autopilotOn) then
  153.         screen.setColor(0,0,0,255)
  154.         screen.drawRectF(screen.getWidth()/4, screen.getHeight()-10, screen.getWidth()/2, 7)
  155.         screen.setColor(255,150,0,255)
  156.         screen.drawRect(screen.getWidth()/4, screen.getHeight()-10, screen.getWidth()/2, 7)
  157.         screen.drawTextBox(screen.getWidth()/4, screen.getHeight()-10, screen.getWidth()/2, 7, "AP On", 0, 0)
  158.     end
  159.    
  160.     screen.setColor(255,150,0,255)
  161.     screen.drawTextBox(1, 1, screen.getWidth()/4-1, screen.getHeight()-dial1.size*2-5-1, ""..math.floor(dial1.value).."", -1, -1)
  162.     screen.drawTextBox(screen.getWidth()/4*3+1, 1, screen.getWidth()/4-1, screen.getHeight()-dial2.size*2-5-1, ""..math.floor(dial2.value).."", 1, -1)
  163.    
Add Comment
Please, Sign In to add comment