Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- <meta charset="utf-8">
- <meta name="mobile-web-app-capable" content="yes">
- <style>
- body{ background-color: rgb(0, 0, 0); }
- </style>
- </head>
- <body>
- <canvas id="base" style="position: absolute; left: 0; top: 0; z-index: 1;"></canvas>
- <canvas id="altb" style="position: absolute; left: 0; top: 0; z-index: 10;"></canvas>
- <canvas id="spdb" style="position: absolute; left: 0; top: 0; z-index: 11;"></canvas>
- <canvas id="hdgb" style="position: absolute; left: 0; top: 0; z-index: 12;"></canvas>
- <canvas id="hor" style="position: absolute; left: 0; top: 0; z-index: 20;"></canvas>
- <canvas id="btn" style="position: absolute; left: 0; top: 0; z-index: 30;"></canvas>
- <script>
- var canvas=document.getElementById("base");
- var ctx=canvas.getContext("2d");
- ctx.canvas.width = window.innerWidth;
- ctx.canvas.height = window.innerHeight;
- //----an insane number of variables.... I'm sorry----
- var WWidth = window.innerWidth;
- var WHeight = window.innerHeight;
- var Scale = 0;
- var con = "false";
- var IP = "127.0.0.1:8085";
- var ip = 0;
- var Alt = 0;
- var AAlt = 0;
- var GrDist = 0;
- var AGrDist = 0;
- var AP = 0;
- var AAP = 0;
- var PE = 0;
- var APE = 0;
- var Spd = 0;
- var ASpd = 0;
- var SpdHor = 0;
- var ASpdHor = 0;
- var SpdVert = 0;
- var ASpdVert = 0;
- var Sx = 0;
- var Sx_m = 0;
- var Sy = 0;
- var Sz = 0;
- var Body ="";
- var Tar = "";
- var Roll = 0;
- var Pitch = 0;
- var Yaw = 0;
- var AYaw = 0;
- var PPitch = 0;
- var PYaw = 0;
- var PRoll = 0;
- var TPitch = 0;
- var TYaw = 0;
- var TRoll = 0;
- var TDist = 0;
- var Inc = 0;
- var Ecc = 0;
- var Per = 0
- var TrA = 0;
- var TTA = 0;
- var TTP = 0;
- var Long = 0;
- var Lat = 0;
- var LongAlt = 0;
- var LatAlt = 0;
- var MET = 0;
- var mode = 2;
- var mj = 0;
- var atmo = 1;
- var light = "";
- var sas = "";
- var gear ="";
- var rcs = "";
- var ass = "";
- var brake = "";
- var gee = 0;
- var thrust = 0;
- var lf_s = 0;
- var lf_s_max = 0;
- var sf_s = 0;
- var sf_s_max = 0;
- var ox_s = 0;
- var ox_s_max = 0;
- var mono = 0;
- var mono_max = 0;
- var charge = 0;
- var charge_max = 0;
- var intake = 0;
- var intake_max = 0;
- var xenon = 0;
- var xenon_max = 0;
- var lf_s_r = 0;
- var sf_s_r = 0;
- var ox_s_r = 0;
- var mono_r = 0;
- var charge_r = 0;
- var xenon_r = 0;
- var delt = 1;
- var rst = true;
- var btn = false;
- var load = true;
- var disp = 1;
- var ag = 0;
- var ab = false;
- WWidth = window.innerWidth;
- WHeight = window.innerHeight;
- if(WWidth/1920<WHeight/1080){
- Scale = WWidth/1920;
- }else{
- Scale = WHeight/1080;
- }
- var CenterX = 700 * Scale;
- var CenterY = 540 * Scale;
- var Width = 116*Scale;
- var Height = 50*Scale;
- var lblue = "rgba(199,237,240,1)";
- var blue = "rgba(74,166,182,1)";
- var lred = "rgba(212,95,87,1)";
- var red = "rgba(148, 38,44,1)";
- var bg = "rgba(26,26,26,1)";
- var white = "rgba(255,255,255,1)";
- var setbg = "rgba(26,26,26,1)";
- var blblue = "rgba(199,237,240,1)";
- var bblue = "rgba(74,166,182,1)";
- var blred = "rgba(212,95,87,1)";
- var bred = "rgba(148, 38,44,1)";
- var bbg = "rgba(0,0,0,1)";
- var bsetbg = "rgba(26,26,26,1)";
- var bwhite = "rgba(255,255,255,1)";
- var res;
- var pg = 0;
- var rate = 200;
- var set = false;
- function load_Data(){ //load settings from localStorage, or use default values when no stored data
- var temp = "";
- if (localStorage.getItem('Rate')) {
- rate = localStorage.getItem('Rate');
- }else{
- rate = 100;
- }
- if (localStorage.getItem('IP')) {
- IP = localStorage.getItem('IP');
- }else{
- IP = "127.0.0.1:8085";
- }
- if (localStorage.getItem('C1')) {
- temp = localStorage.getItem('C1');
- blue = "rgba("+temp+",1)";
- }else{
- blue = bblue;
- }
- if (localStorage.getItem('C2')) {
- temp = localStorage.getItem('C2');
- red = "rgba("+temp+",1)";
- }else{
- red = bred;
- }
- if (localStorage.getItem('H1')) {
- temp = localStorage.getItem('H1');
- lblue = "rgba("+temp+",1)";
- }else{
- lblue = blblue;
- }
- if (localStorage.getItem('H2')) {
- temp = localStorage.getItem('H2');
- lred = "rgba("+temp+",1)";
- }else{
- lred = blred;
- }
- if (localStorage.getItem('BG')) {
- temp = localStorage.getItem('BG');
- bg = "rgba("+temp+",1)";
- }else{
- bg = bbg;
- }
- if (localStorage.getItem('MK')) {
- temp = localStorage.getItem('MK');
- white = "rgba("+temp+",1)";
- }else{
- white = bwhite;
- }
- }
- load_Data();
- //----connect to webSocket----
- var connection = new WebSocket('ws://'+IP+'/datalink');
- connection.onopen = function () { //connection established
- console.log('Connected');
- connection.send('{"+":["tar.name","tar.distance","v.missionTime","v.body","o.timeToAp","o.timeToPe","o.trueAnomaly","o.ApA","o.PeA","o.inclination","o.eccentricity","o.period","f.throttle","v.altitude","v.heightFromTerrain","n.pitch","n.roll","n.heading","v.verticalSpeed","v.surfaceVelocity","v.surfaceVelocityx","v.surfaceVelocityy","v.surfaceVelocityy","v.orbitalVelocity","v.geeForce","v.long","v.lat","v.atmosphericDensity","v.rcsValue","v.sasValue","v.lightValue","v.brakeValue","v.gearValue","r.resource[LiquidFuel]","r.resource[Oxidizer]","r.resourceMax[LiquidFuel]","r.resourceMax[Oxidizer]","r.resource[ElectricCharge]","r.resourceMax[ElectricCharge]","r.resource[MonoPropellant]","r.resourceMax[MonoPropellant]","r.resource[SolidFuel]","r.resourceMax[SolidFuel]","r.resource[IntakeAir]","r.resource[XenonGas]","r.resourceMax[IntakeAir]","r.resourceMax[XenonGas]","r.resourceCurrent[LiquidFuel]","r.resourceCurrent[Oxidizer]","r.resourceCurrent[ElectricCharge]","r.resourceCurrent[MonoPropellant]","r.resourceCurrent[Solid]","r.resourceCurrent[IntakeAir]","r.resourceCurrent[XenonGas]","rate":'+rate+'}');
- con = "true";
- };
- connection.onmessage = function (evt) { //when data is received
- var obj = JSON.parse(evt.data);
- //----store old data to analyse difference----
- LongAlt = Long;
- LatAlt = Lat;
- AAlt = Alt;
- AGrDist = GrDist;
- ASpd = Spd;
- ASpdHor = SpdHor;
- ASpdVert = SpdVert;
- AYaw = Yaw;
- AAP = AP;
- APE = PE;
- lf_s_r = lf_s;
- ox_s_r = ox_s;
- mono_r = mono;
- charge_r = charge;
- xenon_r = xenon;
- sf_s_r = sf_s;
- //----read new data----
- Alt = document.getElementById("base").innerHTML=obj["v.altitude"];
- GrDist = document.getElementById("base").innerHTML=obj["v.heightFromTerrain"];
- AP = document.getElementById("base").innerHTML=obj["o.ApA"];
- PE = document.getElementById("base").innerHTML=obj["o.PeA"];
- Roll = document.getElementById("base").innerHTML=obj["n.roll"];
- Pitch = document.getElementById("base").innerHTML=obj["n.pitch"];
- Yaw = document.getElementById("base").innerHTML=obj["n.heading"];
- Inc = document.getElementById("base").innerHTML=obj["o.inclination"];
- Ecc = document.getElementById("base").innerHTML=obj["o.eccentricity"];
- Per = document.getElementById("base").innerHTML=obj["o.period"];
- TTA = document.getElementById("base").innerHTML=obj["o.timeToAp"];
- TTP = document.getElementById("base").innerHTML=obj["o.timeToPe"];
- TrA = document.getElementById("base").innerHTML=obj["o.trueAnomaly"];
- Long = document.getElementById("base").innerHTML=obj["v.long"];
- Lat = document.getElementById("base").innerHTML=obj["v.lat"];
- Spd = document.getElementById("base").innerHTML=obj["v.orbitalVelocity"];
- SpdHor = document.getElementById("base").innerHTML=obj["v.surfaceVelocity"];
- SpdVert = document.getElementById("base").innerHTML=obj["v.verticalSpeed"];
- Sx_m = document.getElementById("base").innerHTML=obj["v.surfaceVelocityx"];
- Sy = document.getElementById("base").innerHTML=obj["v.surfaceVelocityy"];
- gee = document.getElementById("base").innerHTML=obj["v.geeForce"];
- atmo = document.getElementById("base").innerHTML=obj["v.atmosphericDensity"];
- rcs = document.getElementById("base").innerHTML=obj["v.rcsValue"];
- sas = document.getElementById("base").innerHTML=obj["v.sasValue"];
- light = document.getElementById("base").innerHTML=obj["v.lightValue"];
- gear = document.getElementById("base").innerHTML=obj["v.gearValue"];
- brake = document.getElementById("base").innerHTML=obj["v.brakeValue"];
- pg = document.getElementById("base").innerHTML=obj["v.angleToPrograde"];
- lf_s = document.getElementById("base").innerHTML=obj["r.resource[LiquidFuel]"];
- lf_s_max = document.getElementById("base").innerHTML=obj["r.resourceMax[LiquidFuel]"];
- sf_s = document.getElementById("base").innerHTML=obj["r.resource[SolidFuel]"];
- sf_s_max = document.getElementById("base").innerHTML=obj["r.resourceMax[SolidFuel]"];
- ox_s = document.getElementById("base").innerHTML=obj["r.resource[Oxidizer]"];
- ox_s_max = document.getElementById("base").innerHTML=obj["r.resourceMax[Oxidizer]"];
- mono = document.getElementById("base").innerHTML=obj["r.resource[MonoPropellant]"];
- mono_max = document.getElementById("base").innerHTML=obj["r.resourceMax[MonoPropellant]"];
- charge = document.getElementById("base").innerHTML=obj["r.resource[ElectricCharge]"];
- charge_max = document.getElementById("base").innerHTML=obj["r.resourceMax[ElectricCharge]"];
- intake = document.getElementById("base").innerHTML=obj["r.resource[IntakeAir]"];
- intake_max = document.getElementById("base").innerHTML=obj["r.resource[IntakeAir]"];
- xenon = document.getElementById("base").innerHTML=obj["r.resourceMax[IntakeAir]"];
- xenon_max = document.getElementById("base").innerHTML=obj["r.resourceMax[XenonGas]"];
- //lf_s_r = document.getElementById("base").innerHTML=obj["r.resourceCurrent[LiquidFuel]"];
- //sf_s_r = document.getElementById("base").innerHTML=obj["r.resourceCurrent[Solid]"];
- //ox_s_r = document.getElementById("base").innerHTML=obj["r.resourceCurrent[Oxidizer]"];
- //mono_r = document.getElementById("base").innerHTML=obj["r.resourceCurrent[MonoPropellant]"];
- //charge_r = document.getElementById("base").innerHTML=obj["r.resourceCurrent[ElectricCharge]"];
- //xenon_r = document.getElementById("base").innerHTML=obj["r.resourceCurrent[XenonGas]"];
- thrust = document.getElementById("base").innerHTML=obj["f.throttle"];
- Body = document.getElementById("base").innerHTML=obj["v.body"];
- Tar = document.getElementById("base").innerHTML=obj["tar.name"];
- TDist = document.getElementById("base").innerHTML=obj["tar.distance"];
- if(Body == ""){
- Body = "NO INF";
- }
- //----make window resizeable----
- WWidth = window.innerWidth;
- WHeight = window.innerHeight;
- if(WWidth/1920<WHeight/1080){
- Scale = WWidth/1920;
- }else{
- Scale = WHeight/1080;
- }
- CenterX = 700*Scale;
- CenterY = 540*Scale;
- Width = 116*Scale;
- Height = 50*Scale;
- ctx.canvas.width = window.innerWidth;
- ctx.canvas.height = window.innerHeight;
- PPitch = (180/Math.PI)*Math.atan(SpdVert/SpdHor);
- //PYaw = (-180/Math.PI)*Math.atan(Sx/Sy);
- //if(Sx<0 && Sy<0){
- // PYaw+=180;
- //}
- //if(Sx>=0 && Sy<0){
- // PYaw+=180;
- //}
- //if(Sx>=0 && Sy>=0){
- // PYaw+=360;
- //}
- //if(Sx < 0 && Sy>=0){
- //}
- //if(Sx==0 && Sy==0){
- // PYaw = Yaw;
- //}
- //----calculate prograde angles----
- PYaw = (180/Math.PI)*Math.atan((Long-LongAlt)/((Lat-LatAlt)*(1/Math.cos(Lat*Math.PI/180))));
- if(Lat-LatAlt==0){
- if(Long-LongAlt>0){
- PYaw = 90;
- }else{
- PYaw = 270;
- }
- }
- if(Lat-LatAlt<0 && Long-LongAlt>=0){
- PYaw+=180;
- }
- if(Lat-LatAlt<0 && Long-LongAlt<0){
- PYaw+=180;
- }
- if(Lat-LatAlt>=0 && Long-LongAlt<0){
- PYaw+=360;
- }
- if(Lat-LatAlt>=0 && Long-LongAlt>=0){
- }
- if(Long-LongAlt==0 && Lat-LatAlt==0){
- PYaw = Yaw;
- }
- //----draw all the things!---
- draw_altBar(Alt, AAlt, GrDist, AGrDist, AP, AAP, PE, APE);
- if(mode == 2){
- draw_speedbar(Math.sqrt(SpdHor*SpdHor+SpdVert*SpdVert), Math.sqrt(ASpdHor*ASpdHor+ASpdVert*ASpdVert), SpdHor, ASpdHor, SpdVert, ASpdVert);
- }else{
- draw_speedbar(Spd, ASpd, SpdHor, ASpdHor, SpdVert, ASpdVert);
- }
- draw_hdgbar(Yaw, AYaw, Roll, Pitch);
- draw_ah(Pitch, Yaw, Roll);
- draw_buttons();
- };
- connection.onerror = function (error) { //connection error
- con = "err";
- console.log('WebSocket Error ' + error.data);
- set = true;
- };
- connection.onclose = function () { //connection closed
- console.log('Disconnected');
- con = "false";
- draw_ah(0, 0, 0);
- draw_altBar(0, 0, 0, 0, 0, 0, 0, 0);
- draw_speedbar(0, 0, 0, 0, 0, 0);
- draw_hdgbar(0, 0, 0, 0, 0, 0);
- gee = 0;
- draw_buttons();
- set = true;
- };
- if(con=="false"){ //not connected
- draw_ah(0, 0, 0);
- draw_altBar(0, 0, 0, 0, 0, 0, 0);
- draw_speedbar(0, 0, 0, 0, 0, 0);
- draw_hdgbar(0, 0, 0, 0, 0, 0);
- gee = 0;
- draw_buttons();
- }
- //----functions for things to draw----
- function draw_altBar(alt, aalt, grdist, agrdist, ap, aap, pe, ape, gr){
- var canvas=document.getElementById("altb");
- var ctx=canvas.getContext("2d");
- ctx.canvas.width = window.innerWidth;
- ctx.canvas.height = window.innerHeight;
- ctx.clearRect(StartX-200*Scale, StartY-400*Scale, 400*Scale, 800*Scale);
- ctx.fillStyle = bg;
- ctx.fillRect(0,0, WWidth, WHeight);
- var StartX = 515*Scale+CenterX;
- var StartY = 515*Scale;
- var exponent = 1;
- var div = 1;
- var print = 0;
- var Unit = "";
- var print = 0;
- var Width = 116*Scale;
- var Height = 50*Scale;
- var lz = "";
- var m = 0;
- draw_bar(alt, ap, pe, grdist);
- draw_ind(alt, aalt, StartX, StartY, "ALT", 0.00001)
- draw_ind(grdist, agrdist, StartX, 1018*Scale, "GrdDist", 0.00001)
- draw_ind(ap, aap, StartX, 50*Scale, "AP", 0.0001)
- draw_ind(pe, ape, StartX, 65*Scale+Height, "PE", 0.0001)
- function draw_bar(v, vap, vpe, vgr){ //draw alitutde bar
- var dy = 0;
- var dx = 0;
- var rad = 500*Scale;
- var deltx = 0;
- var delty = 40*Scale;
- if(Math.abs(v) < 10){ //calculate unit, step width and exponent
- exponent = 1;
- div = 1;
- Unit = "m";
- }else if(Math.abs(v) >= 10 && Math.abs(v) < 100){
- exponent = 1;
- div = 5;
- Unit = "m";
- }else if(Math.abs(v) >= 100 && Math.abs(v) < 1000){
- exponent = 1;
- div = 10;
- Unit = "m";
- }else if(Math.abs(v) >= 1000 && Math.abs(v) < 10000){
- exponent = 1;
- div = 100;
- Unit = "m";
- }else if(Math.abs(v) >= 10000 && Math.abs(v) < 100000){
- exponent = 1;
- div = 500;
- Unit = "m";
- }else if(Math.abs(v) >= 100000 && Math.abs(v) < 1000000){
- exponent = 1000;
- div = 5000;
- Unit = "km";
- }else if(Math.abs(v) >= 1000000 && Math.abs(v) < 10000000){
- exponent = 1000;
- div = 10000;
- Unit = "km";
- }else if(Math.abs(v) >= 10000000 && Math.abs(v) < 100000000){
- exponent = 1000;
- div = 100000;
- Unit = "km";
- }else{
- exponent = 1000000;
- div = 1000000;
- Unit = "Mm";
- }
- for(i=-10;i<=9;i++){ //draw items of altitude bar
- print=Math.floor(v/div)*div+(i+1)*div;
- m = print/exponent;
- if(m<10 && m >= 0){ //format string
- lz = "00 00"+Math.floor(m);
- }else if(m < 100 && m >= 10){
- lz = "00 0"+Math.floor(m);
- }else if(m < 1000 && m >= 100){
- lz = "00 "+Math.floor(m);
- }else if(m < 10000 && m >= 1000){
- lz = "0"+m.toFixed(0).slice(0,1)+" "+m.toFixed(0).slice(1,4);
- }else if(m < 0 && m > -9){
- lz = ("-0 00" + Math.abs(m.toFixed()));
- }else if(m <= -10 && m > -99){
- lz = ("-00 " + Math.abs(m.toFixed()));
- }else if(m <= -100 && m > -999){
- lz = ("-0 " + Math.abs(m.toFixed()));
- }else{
- lz = m.toFixed(0).slice(0,2)+" "+m.toFixed(0).slice(2,5);
- }
- if(i>=0){
- ctx.fillStyle=blue;
- ctx.strokeStyle=blue;
- }else{
- ctx.fillStyle=red;
- ctx.strokeStyle=red;
- }
- deltx = 4*Scale+(-(i+1)*delty+delty*((v/div)-Math.floor(v/div)))*Math.tan(0.5*Math.asin((-(i+1)*delty+delty*((v/div)-Math.floor(v/div)))/rad));
- ctx.lineWidth = 1*Scale;
- ctx.font = 22*Scale+'pt Courier New';
- ctx.textAlign = 'right';
- ctx.fillText(lz, StartX-deltx+Width, StartY+24*Scale-(i+1)*delty+delty*((v/div)-Math.floor(v/div)));
- ctx.strokeText(lz, StartX-deltx+Width, StartY+24*Scale-(i+1)*delty+delty*((v/div)-Math.floor(v/div)));
- ctx.fillStyle="transparent";
- }
- dy = delty*(ap - v)/(div);
- dx = dy*Math.tan(0.5*Math.asin(dy/rad));
- if(Math.abs(dy+16*Scale)<350*Scale && Math.abs(dy+16*Scale)>25*Scale){ //draw apoapsis indicator
- ctx.fillStyle = blue;
- ctx.strokeStyle = blue;
- ctx.font = 18*Scale+'pt Courier New';
- ctx.textAlign = 'center';
- ctx.beginPath();
- ctx.moveTo(StartX+120*Scale-dx,StartY+16*Scale-dy);
- ctx.lineTo(StartX+120*Scale+30*Scale-dx,StartY-5*Scale+16*Scale-dy);
- ctx.lineTo(StartX+120*Scale+30*Scale-dx,StartY+5*Scale+16*Scale-dy);
- ctx.closePath();
- ctx.fill();
- ctx.fillText("AP", StartX+135*Scale-dx,StartY-dy);
- ctx.strokeText("AP", StartX+135*Scale-dx,StartY-dy);
- }
- dy = delty*(vpe - v)/(div);
- dx = dy*Math.tan(0.5*Math.asin(dy/rad));
- if(Math.abs(dy+16*Scale)<350*Scale && Math.abs(dy+16*Scale)>25*Scale){ //draw periapsis indicator
- ctx.fillStyle = red;
- ctx.strokeStyle = red;
- ctx.font = 18*Scale+'pt Courier New';
- ctx.textAlign = 'center';
- ctx.beginPath();
- ctx.moveTo(StartX+120*Scale-dx,StartY+16*Scale-dy);
- ctx.lineTo(StartX+120*Scale+30*Scale-dx,StartY-5*Scale+16*Scale-dy);
- ctx.lineTo(StartX+120*Scale+30*Scale-dx,StartY+5*Scale+16*Scale-dy);
- ctx.closePath();
- ctx.fill();
- ctx.fillText("PE", StartX+135*Scale-dx,StartY-dy+44*Scale);
- ctx.strokeText("PE", StartX+135*Scale-dx,StartY-dy+44*Scale);
- }
- dy = delty*(-vgr)/(div);
- dx = dy*Math.tan(0.5*Math.asin(dy/rad));
- if(Math.abs(dy+16*Scale)<350*Scale && Math.abs(dy+16*Scale)>25*Scale && vgr != -1){ //draw ground indicator
- ctx.fillStyle = red;
- ctx.strokeStyle = red;
- ctx.font = 18*Scale+'pt Courier New';
- ctx.textAlign = 'center';
- ctx.beginPath();
- ctx.moveTo(StartX+120*Scale-dx,StartY+16*Scale-dy);
- ctx.lineTo(StartX+120*Scale+30*Scale-dx,StartY-5*Scale+16*Scale-dy);
- ctx.lineTo(StartX+120*Scale+30*Scale-dx,StartY+5*Scale+16*Scale-dy);
- ctx.closePath();
- ctx.fill();
- ctx.fillText("GRND", StartX+135*Scale-dx,StartY-dy+44*Scale);
- ctx.strokeText("GRND", StartX+135*Scale-dx,StartY-dy+44*Scale);
- }
- var grd1=ctx.createLinearGradient(0,StartY-delty*9,0,StartY-delty*7); //draw gradients to cover top and bottom of the bar
- var grd2=ctx.createLinearGradient(0,StartY+delty*8,0,StartY+delty*10);
- grd1.addColorStop(0,bg);
- grd1.addColorStop(0.75,bg.slice(0,-3)+",0.5)");
- grd1.addColorStop(1,bg.slice(0,-3)+",0)");
- grd2.addColorStop(0,bg.slice(0,-3)+",0)");
- grd2.addColorStop(0.25,bg.slice(0,-3)+",0.5)");
- grd2.addColorStop(1,bg);
- ctx.fillStyle=grd1;
- ctx.fillRect(StartX-200*Scale,StartY-delty*10, 300*Scale,3*delty);
- ctx.fillStyle=grd2;
- ctx.fillRect(StartX-200*Scale,StartY+delty*8,300*Scale,3*delty);
- } //end draw_bar
- function draw_ind(v, av, x, y, t, delta){ //draw altitude indicator
- if(Math.abs(v) < 10){ //calculate unit and exponent
- exponent = 1;
- Unit = "m";
- }else if(Math.abs(v) >= 10 && Math.abs(v) < 100){
- exponent = 1;
- Unit = "m";
- }else if(Math.abs(v) >= 100 && Math.abs(v) < 1000){
- exponent = 1;
- Unit = "m";
- }else if(Math.abs(v) >= 1000 && Math.abs(v) < 10000){
- exponent = 1;
- Unit = "m";
- }else if(Math.abs(v) >= 10000 && Math.abs(v) < 100000){
- exponent = 1;
- Unit = "m";
- }else if(Math.abs(v) >= 100000 && Math.abs(v) < 1000000){
- exponent = 1000;
- Unit = "km";
- }else if(Math.abs(v) >= 1000000 && Math.abs(v) < 10000000){
- exponent = 1000;
- Unit = "km";
- }else if(Math.abs(v) >= 10000000 && Math.abs(v) < 100000000){
- exponent = 1000;
- Unit = "km";
- }else{
- exponent = 1000000;
- Unit = "Mm";
- }
- m=v/(exponent);
- if(m<10 && m >= 0){ //format string
- lz = "00 00"+Math.floor(m);
- }else if(m < 100 && m >= 10){
- lz = "00 0"+Math.floor(m);
- }else if(m < 1000 && m >= 100){
- lz = "00 "+Math.floor(m);
- }else if(m < 10000 && m >= 1000){
- lz = "0"+m.toFixed(0).slice(0,1)+" "+m.toFixed(0).slice(1,4);
- }else if(m < 0 && m > -9){
- lz = ("-0 00" + Math.abs(m.toFixed()));
- }else if(m <= -10 && m > -99){
- lz = ("-00 " + Math.abs(m.toFixed()));
- }else if(m <= -100 && m > -999){
- lz = ("-0 " + Math.abs(m.toFixed()));
- }else{
- lz = m.toFixed(0).slice(0,2)+" "+m.toFixed(0).slice(2,5);
- }
- if(v==-1 && av==-1){ //draw error when no info
- lz = "NO INF";
- Unit = "";
- }
- ctx.fillStyle=blue;
- ctx.fillRect(x,y,Width,Height);
- ctx.font = 18*Scale+'pt Lucida Console';
- ctx.textAlign = 'left';
- ctx.fillStyle = blue;
- ctx.fillText(Unit, x+Width+8*Scale, y+32*Scale);
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = blue;
- ctx.strokeText(Unit, x+Width+8*Scale, y+32*Scale);
- ctx.font = 22*Scale+'pt Courier New';
- ctx.textAlign = 'right';
- ctx.fillStyle = lblue;
- ctx.fillText(lz, x+Width-4*Scale, y+24*Scale);
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = lblue;
- ctx.strokeText(lz, x+Width-4*Scale, y+24*Scale);
- ctx.font = 10*Scale+'pt Courier New';
- ctx.textAlign = 'left';
- ctx.fillText(t, x+8*Scale, y+Height-8*Scale);
- //ctx.strokeText(t, x+8*Scale, y+Height-8*Scale);
- if(Math.abs((v-av)/v)>delta){ //draw change indicator
- if(v-av>0 && Math.abs((v-av)/v) < 0.01){
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.moveTo(x-10*Scale,y+15*Scale);
- ctx.lineTo(x-15*Scale,y+Height-15*Scale);
- ctx.lineTo(x-5*Scale,y+Height-15*Scale);
- ctx.closePath();
- ctx.fill();
- }else if(v-av>0 && Math.abs((v-av)/v) >= 0.01){
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.moveTo(x-10*Scale,y+5*Scale);
- ctx.lineTo(x-15*Scale,y+Height/2);
- ctx.lineTo(x-5*Scale,y+Height/2);
- ctx.closePath();
- ctx.fill();
- ctx.beginPath();
- ctx.moveTo(x-10*Scale,y+Height/2);
- ctx.lineTo(x-15*Scale,y+Height-5*Scale);
- ctx.lineTo(x-5*Scale,y+Height-5*Scale);
- ctx.closePath();
- ctx.fill();
- }else if(v-av<0 && Math.abs((v-av)/v) < 0.01){
- ctx.fillStyle = red;
- ctx.beginPath();
- ctx.moveTo(x-5*Scale,y+15*Scale);
- ctx.lineTo(x-15*Scale,y+15*Scale);
- ctx.lineTo(x-10*Scale,y+Height-15*Scale);
- ctx.closePath();
- ctx.fill();
- }else if(v-av<0 && Math.abs((v-av)/v) >= 0.01){
- ctx.fillStyle = red;
- ctx.beginPath();
- ctx.moveTo(x-5*Scale,y+5*Scale);
- ctx.lineTo(x-15*Scale,y+5*Scale);
- ctx.lineTo(x-10*Scale,y+Height/2);
- ctx.closePath();
- ctx.fill();
- ctx.beginPath();
- ctx.moveTo(x-5*Scale,y+Height/2);
- ctx.lineTo(x-15*Scale,y+Height/2);
- ctx.lineTo(x-10*Scale,y+Height-5*Scale);
- ctx.closePath();
- ctx.fill();
- }
- }
- } //end draw_ind
- } //end draw_altbar
- function draw_speedbar(spd, aspd, spd_hor, aspd_hor, spd_vert, aspd_vert){
- var canvas=document.getElementById("spdb");
- var ctx=canvas.getContext("2d");
- ctx.canvas.width = window.innerWidth;
- ctx.canvas.height = window.innerHeight;
- var Width = 116*Scale;
- var Height = 50*Scale;
- var StartX = -527*Scale+CenterX;
- var StartY = 515*Scale;
- var Rad = 0;
- var exponent = 1;
- var print = 0;
- var deltx = 0;
- var lz = "";
- var dif = 0;
- ctx.clearRect(0, 0, 1920*Scale, 1080*Scale);
- function draw_indicator(x, y, w, h, v, av, t){ //draw speed indcator
- var m = 0;
- var deltx = 0;
- if(Math.abs(v) < 10){ //calculate unit and exponent
- exponent = 1;
- Unit = "m";
- }else if(Math.abs(v) >= 10 && Math.abs(v) < 100){
- exponent = 1;
- Unit = "m";
- }else if(Math.abs(v) >= 100 && Math.abs(v) < 1000){
- exponent = 1;
- Unit = "m";
- }else if(Math.abs(v) >= 1000 && Math.abs(v) < 10000){
- exponent = 1;
- Unit = "m";
- }else if(Math.abs(v) >= 10000 && Math.abs(v) < 100000){
- exponent = 1;
- Unit = "m";
- }else if(Math.abs(v) >= 100000 && Math.abs(v) < 1000000){
- exponent = 1000;
- Unit = "km";
- }else if(Math.abs(v) >= 1000000 && Math.abs(v) < 10000000){
- exponent = 1000;
- Unit = "km";
- }else if(Math.abs(v) >= 10000000 && Math.abs(v) < 100000000){
- exponent = 1000;
- Unit = "km";
- }else{
- exponent = 1000000;
- Unit = "Mm";
- }
- m = v/exponent;
- if(m<10 && m >= 0){ //format string
- lz = "00 00"+Math.floor(m);
- }else if(m < 100 && m >= 10){
- lz = "00 0"+Math.floor(m);
- }else if(m < 1000 && m >= 100){
- lz = "00 "+Math.floor(m);
- }else if(m < 10000 && m >= 1000){
- lz = "0"+m.toFixed(0).slice(0,1)+" "+m.toFixed(0).slice(1,4);
- }else if(m < 0 && m > -10){
- lz = ("-0 00" + Math.abs(Math.floor(m)));
- }else if(m <= -10 && m > -100){
- lz = ("-0 0" + Math.abs(Math.floor(m)));
- }else if(m <= -100 && m > -1000){
- lz = ("-0 " + Math.abs(Math.floor(m)));
- }else if(m <= -1000 && m > -10000){
- lz = ("-" + Math.abs(Math.floor(m)));
- }else if(m <= -10000 && m > -100000){
- lz = ("-" + Math.abs(Math.floor(m)));
- }else{
- lz = m.toFixed(0).slice(0,2)+" "+m.toFixed(0).slice(2,5);
- }
- ctx.fillStyle=blue;
- ctx.fillRect(x, y, w, h);
- ctx.font = 18*Scale+'pt Lucida Console';
- ctx.textAlign = 'left';
- ctx.fillStyle = blue;
- ctx.fillText(Unit, x+w+8*Scale, y+16*Scale);
- ctx.fillText("s", x+w+8*Scale+deltx, y+46*Scale);
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = blue;
- ctx.strokeText(Unit, x+w+8*Scale, y+16*Scale);
- ctx.strokeText("s", x+w+8*Scale+deltx, y+46*Scale);
- ctx.beginPath();
- ctx.lineWidth = 2*Scale;
- ctx.moveTo(x+w+4*Scale, y+h/2);
- ctx.lineTo(x+w+26*Scale+2*deltx, y+h/2);
- ctx.stroke();
- ctx.font = 22*Scale+'pt Courier New';
- ctx.textAlign = 'right';
- ctx.fillStyle = lblue;
- ctx.fillText(lz, x+w-4*Scale, y+24*Scale);
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = lblue;
- ctx.strokeText(lz, x+w-4*Scale, y+24*Scale);
- ctx.font = 10*Scale+'pt Courier New';
- ctx.textAlign = 'left';
- ctx.fillText(t, x+8*Scale, y+h-8*Scale);
- //ctx.strokeText(t, x+8*Scale, y+h-8*Scale);
- if(Math.abs(v-av)>0.02){ //draw change indicator
- if(v-av>0.01 && Math.abs(v-av)/v < 0.1){
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.moveTo(x-10*Scale,y+15*Scale);
- ctx.lineTo(x-15*Scale,y+Height-15*Scale);
- ctx.lineTo(x-5*Scale,y+Height-15*Scale);
- ctx.closePath();
- ctx.fill();
- }else if(v-av>0.01 && Math.abs(v-av)/v >= 0.1){
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.moveTo(x-10*Scale,y+5*Scale);
- ctx.lineTo(x-15*Scale,y+Height/2);
- ctx.lineTo(x-5*Scale,y+Height/2);
- ctx.closePath();
- ctx.fill();
- ctx.beginPath();
- ctx.moveTo(x-10*Scale,y+Height/2);
- ctx.lineTo(x-15*Scale,y+Height-5*Scale);
- ctx.lineTo(x-5*Scale,y+Height-5*Scale);
- ctx.closePath();
- ctx.fill();
- }else if(v-av<0.01 && Math.abs(v-av)/v < 0.1){
- ctx.fillStyle = red;
- ctx.beginPath();
- ctx.moveTo(x-5*Scale,y+15*Scale);
- ctx.lineTo(x-15*Scale,y+15*Scale);
- ctx.lineTo(x-10*Scale,y+Height-15*Scale);
- ctx.closePath();
- ctx.fill();
- }else if(v-av<0.01 && Math.abs(v-av)/v >= 0.1){
- ctx.fillStyle = red;
- ctx.beginPath();
- ctx.moveTo(x-5*Scale,y+5*Scale);
- ctx.lineTo(x-15*Scale,y+5*Scale);
- ctx.lineTo(x-10*Scale,y+Height/2);
- ctx.closePath();
- ctx.fill();
- ctx.beginPath();
- ctx.moveTo(x-5*Scale,y+Height/2);
- ctx.lineTo(x-15*Scale,y+Height/2);
- ctx.lineTo(x-10*Scale,y+Height-5*Scale);
- ctx.closePath();
- ctx.fill();
- }
- }
- } //end draw_indicator
- function draw_bar_s(v, startx, starty, delty, min){ //draw straight speed bar
- if(Math.abs(v) < 9){ //calculate unit, step width and exponent
- exponent = 1;
- div = 1;
- Unit = "m";
- }else if(Math.abs(v) >= 10 && Math.abs(v) < 100){
- exponent = 1;
- div = 5;
- Unit = "m";
- }else if(Math.abs(v) >= 100 && Math.abs(v) < 1000){
- exponent = 1;
- div = 10;
- Unit = "m";
- }else if(Math.abs(v) >= 1000 && Math.abs(v) < 10000){
- exponent = 1;
- div = 100;
- Unit = "m";
- }else if(Math.abs(v) >= 10000 && Math.abs(v) < 100000){
- exponent = 1;
- div = 500;
- Unit = "m";
- }else if(Math.abs(v) >= 100000 && Math.abs(v) < 1000000){
- exponent = 1000;
- div = 1000;
- Unit = "km";
- }else if(Math.abs(v) >= 1000000 && Math.abs(v) < 10000000){
- exponent = 1000;
- div = 10000;
- Unit = "km";
- }else if(Math.abs(v) >= 10000000 && Math.abs(v) < 100000000){
- exponent = 1000;
- div = 100000;
- Unit = "km";
- }else{
- exponent = 1000000;
- div = 1000000;
- Unit = "Mm";
- }
- for(i=-4;i<=3;i++){ //draw items
- print=Math.floor(v/(exponent*div))*div+(i+1)*div;
- m = print/exponent;
- if(m<10 && m >= 0){ //format string
- lz = "00 00"+Math.floor(m);
- }else if(m < 100 && m >= 10){
- lz = "00 0"+Math.floor(m);
- }else if(m < 1000 && m >= 100){
- lz = "00 "+Math.floor(m);
- }else if(m < 10000 && m >= 1000){
- lz = "0"+m.toFixed(0).slice(0,1)+" "+m.toFixed(0).slice(1,4);
- }else if(m < 0 && m > -10){
- lz = ("-0 00" + Math.abs(Math.floor(m)));
- }else if(m <= -10 && m > -100){
- lz = ("-0 0" + Math.abs(Math.floor(m)));
- }else if(m <= -100 && m > -1000){
- lz = ("-0 " + Math.abs(Math.floor(m)));
- }else if(m <= -1000 && m > -10000){
- lz = ("-" + Math.abs(Math.floor(m)));
- }else if(m <= -10000 && m > -100000){
- lz = ("-" + Math.abs(Math.floor(m)));
- }else{
- lz = m.toFixed(0).slice(0,2)+" "+m.toFixed(0).slice(2,5);
- }
- if(i>=0){ //blue color for items on top
- ctx.fillStyle=blue;
- ctx.strokeStyle=blue;
- }else{ //red color for items on bottom
- ctx.fillStyle=red;
- ctx.strokeStyle=red;
- }
- if(min=="false"){ //draw only positiv or both pos and neg items
- if(print>=0){
- ctx.lineWidth = 1*Scale;
- ctx.font = 22*Scale+'pt Courier New';
- ctx.textAlign = 'right';
- ctx.fillText(lz, startx, starty+24*Scale-(i+1)*delty+delty*(1/div)*((v/(exponent))-Math.floor(v/(exponent*div))*div));
- ctx.strokeText(lz, startx, starty+24*Scale-(i+1)*delty+delty*(1/div)*((v/(exponent))-Math.floor(v/(exponent*div))*div));
- }
- }else if(min=="true"){
- ctx.lineWidth = 1*Scale;
- ctx.font = 22*Scale+'pt Courier New';
- ctx.textAlign = 'right';
- ctx.fillText(lz, startx, starty+24*Scale-(i+1)*delty+delty*(1/div)*((v/(exponent))-Math.floor(v/(exponent*div))*div));
- ctx.strokeText(lz, startx, starty+24*Scale-(i+1)*delty+delty*(1/div)*((v/(exponent))-Math.floor(v/(exponent*div))*div));
- }
- }
- var grd1=ctx.createLinearGradient(0,starty-1.5*delty,0,starty-delty*0.5); //draw gradients on top and bottom
- var grd2=ctx.createLinearGradient(0,starty+delty*2,0,starty+delty*4);
- grd1.addColorStop(0,bg);
- grd1.addColorStop(0.75,bg.slice(0,-3)+",0.5)");
- grd1.addColorStop(1,bg.slice(0,-3)+",0)");
- grd2.addColorStop(0,bg.slice(0,-3)+",0)");
- grd2.addColorStop(0.25,bg.slice(0,-3)+",0.5)");
- grd2.addColorStop(1,bg);
- ctx.fillStyle=grd1;
- ctx.fillRect(startx-116*Scale,0, 116*Scale,2*delty);
- ctx.fillStyle=grd2;
- ctx.fillRect(startx-116*Scale,starty+delty*2, 116*Scale,3*delty);
- } //end draw_bar_s
- function draw_bar_r(v, startx, starty, delty){ //draw curved bar
- var delty = 40*Scale;
- if(Math.abs(v) < 9){ //calculate unit, step width and exponent
- exponent = 1;
- div = 1;
- Unit = "m";
- }else if(Math.abs(v) >= 10 && Math.abs(v) < 100){
- exponent = 1;
- div = 5;
- Unit = "m";
- }else if(Math.abs(v) >= 100 && Math.abs(v) < 1000){
- exponent = 1;
- div = 10;
- Unit = "m";
- }else if(Math.abs(v) >= 1000 && Math.abs(v) < 10000){
- exponent = 1;
- div = 100;
- Unit = "m";
- }else if(Math.abs(v) >= 10000 && Math.abs(v) < 100000){
- exponent = 1;
- div = 500;
- Unit = "m";
- }else if(Math.abs(v) >= 100000 && Math.abs(v) < 1000000){
- exponent = 1000;
- div = 50;
- Unit = "km";
- }else if(Math.abs(v) >= 1000000 && Math.abs(v) < 10000000){
- exponent = 1000;
- div = 500;
- Unit = "km";
- }else if(Math.abs(v) >= 10000000 && Math.abs(v) < 100000000){
- exponent = 1000;
- div = 1000;
- Unit = "km";
- }else{
- exponent = 1000000;
- div = 1000000;
- Unit = "Mm";
- }
- for(i=-10;i<=9;i++){ //draw items
- print=Math.floor(v/(exponent*div))*div+(i+1)*div;
- m = print/exponent;
- if(m<10 && m >= 0){ //format string
- lz = "00 00"+Math.floor(m);
- }else if(m < 100 && m >= 10){
- lz = "00 0"+Math.floor(m);
- }else if(m < 1000 && m >= 100){
- lz = "00 "+Math.floor(m);
- }else if(m < 10000 && m >= 1000){
- lz = "0"+m.toFixed(0).slice(0,1)+" "+m.toFixed(0).slice(1,4);
- }else if(m < 0 && m > -9){
- lz = ("-0 00" + Math.abs(Math.floor(m)));
- }else if(m <= -10 && m > -99){
- lz = ("-0 0" + Math.abs(Math.floor(m)));
- }else if(m <= -10 && m > -99){
- lz = ("-0 " + Math.abs(Math.floor(m)));
- }else{
- lz = m.toFixed(0).slice(0,2)+" "+m.toFixed(0).slice(2,5);
- }
- if(i>=0){ //blue color for items on top
- ctx.fillStyle=blue;
- ctx.strokeStyle=blue;
- }else{ //red color for items on bottom
- ctx.fillStyle=red;
- ctx.strokeStyle=red;
- }
- rad = 500*Scale;
- deltx = (-(i+1)*delty+delty*(1/div)*((v/(exponent))-Math.floor(v/(exponent*div))*div))*Math.tan(0.5*Math.asin((-(i+1)*delty+delty*(1/div)*((v/(exponent))-Math.floor(v/(exponent*div))*div))/rad));
- if(print>=0){ //only draw positiv items
- ctx.lineWidth = 1*Scale;
- ctx.font = 22*Scale+'pt Courier New';
- ctx.textAlign = 'right';
- ctx.fillText(lz, startx+deltx, starty+24*Scale-(i+1)*delty+delty*(1/div)*((v/(exponent))-Math.floor(v/(exponent*div))*div));
- ctx.strokeText(lz, startx+deltx, starty+24*Scale-(i+1)*delty+delty*(1/div)*((v/(exponent))-Math.floor(v/(exponent*div))*div));
- }
- }
- var grd1=ctx.createLinearGradient(0,starty-delty*9,0,starty-delty*7); //draw gradients on top and bottom
- var grd2=ctx.createLinearGradient(0,starty+delty*8,0,starty+delty*10);
- grd1.addColorStop(0,bg);
- grd1.addColorStop(0.75,bg.slice(0,-3)+",0.5)");
- grd1.addColorStop(1,bg.slice(0,-3)+",0)");
- grd2.addColorStop(0,bg.slice(0,-3)+",0)");
- grd2.addColorStop(0.25,bg.slice(0,-3)+",0.5)");
- grd2.addColorStop(1,bg);
- ctx.fillStyle=grd1;
- ctx.fillRect(startx,starty-delty*10, 200*Scale,3*delty);
- ctx.fillStyle=grd2;
- ctx.fillRect(startx,starty+delty*8,200*Scale,3*delty);
- } //end draw_bar_r
- draw_bar_r(spd, StartX, StartY, 40*Scale);
- draw_bar_s(spd_hor, CenterX-300*Scale+Width, 50*Scale, 25*Scale, "false");
- draw_bar_s(spd_vert, CenterX+300*Scale-8*Scale, 50*Scale, 25*Scale, "true");
- draw_indicator(StartX-Width, StartY, Width, Height, spd, aspd, "SPD");
- draw_indicator(CenterX-300*Scale+4*Scale, 50*Scale, Width, Height, spd_hor, aspd_hor, "HorSPD");
- draw_indicator(CenterX+300*Scale-Width-4*Scale, 50*Scale, Width, Height, spd_vert, aspd_vert, "VertSPD");
- } //end draw spdbar
- function draw_hdgbar(yaw, ayaw, roll, pitch){
- var canvas=document.getElementById("hdgb");
- var ctx=canvas.getContext("2d");
- ctx.canvas.width = window.innerWidth;
- ctx.canvas.height = window.innerHeight;
- var Width = 116*Scale;
- var StartX = CenterX-Width/2;
- var StartY = 1018*Scale;
- var print = "";
- var Rad = 0;
- var print = 0;
- var deltx = 50*Scale;
- var delty = 0;
- ctx.clearRect(StartX-400*Scale, StartY-200*Scale, 800*Scale, 400*Scale);
- function draw_bar(v){ //draw heading bar
- for(i=-5;i<=4;i++){
- print=Math.floor(v)+(i+1)*0.5;
- if(print<0){
- print+=360;
- }
- ctx.fillStyle=blue;
- ctx.strokeStyle=blue;
- rad = 800*Scale;
- delty = (25*Scale+2*(i+1)*deltx-deltx*4*(v-Math.floor(v)))*Math.tan(0.5*Math.asin((25*Scale+2*(i+1)*deltx-deltx*4*(v-Math.floor(v)))/rad));
- ctx.lineWidth = 1*Scale;
- ctx.font = 22*Scale+'pt Courier New';
- ctx.textAlign = 'right';
- if((Width-4*Scale+2*(i+1)*deltx-deltx*4*(v-Math.floor(v)))> -300*Scale && (Width-4*Scale+2*(i+1)*deltx-deltx*4*(v-Math.floor(v)))< 450*Scale){
- ctx.fillText(print.toFixed(1), StartX+Width-4*Scale+2*(i+1)*deltx-deltx*4*(v-Math.floor(v)), StartY+24*Scale-delty);
- ctx.strokeText(print.toFixed(1), StartX+Width-4*Scale+2*(i+1)*deltx-deltx*4*(v-Math.floor(v)), StartY+24*Scale-delty);
- }
- }
- var grd1=ctx.createLinearGradient(StartX-300*Scale,0,StartX-100*Scale,0); //draw gradients left and right
- var grd2=ctx.createLinearGradient(StartX+300*Scale,0,StartX+500*Scale,0);
- grd1.addColorStop(0,bg);
- grd1.addColorStop(0.75,bg.slice(0,-3)+",0.5)");
- grd1.addColorStop(1,bg.slice(0,-3)+",0)");
- grd2.addColorStop(0,bg.slice(0,-3)+",0)");
- grd2.addColorStop(0.25,bg.slice(0,-3)+",0.5)");
- grd2.addColorStop(1,bg);
- ctx.fillStyle=grd1;
- ctx.fillRect(StartX-400*Scale,StartY-100*Scale, 300*Scale,100*Scale);
- ctx.fillStyle=grd2;
- ctx.fillRect(StartX+300*Scale,StartY-100*Scale, 300*Scale,100*Scale);
- }
- function draw_indicator(v, av){ //draw heading indicator
- ctx.fillStyle=blue;
- ctx.fillRect(StartX,StartY,Width,Height);
- ctx.font = 22*Scale+'pt Courier New';
- ctx.textAlign = 'right';
- ctx.fillStyle = lblue;
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = lblue;
- ctx.fillText(v.toFixed(1), StartX+Width-4*Scale, StartY+24*Scale);
- ctx.strokeText(v.toFixed(1), StartX+Width-4*Scale, StartY+24*Scale);
- ctx.font = 10*Scale+'pt Courier New';
- ctx.textAlign = 'left';
- ctx.fillText("HDG", StartX+8*Scale, StartY+Height-8*Scale);
- if(Math.abs(v-av)>0.0001){ //draw change indicator
- if(v-av>0 && Math.abs((v-av)) < 0.1){
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.moveTo(StartX+Width/2-10*Scale,StartY-15*Scale);
- ctx.lineTo(StartX+Width/2-10*Scale,StartY-5*Scale);
- ctx.lineTo(StartX+Width/2+10*Scale,StartY-10*Scale);
- ctx.closePath();
- ctx.fill();
- }else if(v-av>0 && Math.abs((v-av)) >= 0.1){
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.moveTo(StartX+Width/2-20*Scale,StartY-15*Scale);
- ctx.lineTo(StartX+Width/2-20*Scale,StartY-5*Scale);
- ctx.lineTo(StartX+Width/2,StartY-10*Scale);
- ctx.closePath();
- ctx.fill();
- ctx.beginPath();
- ctx.moveTo(StartX+Width/2,StartY-15*Scale);
- ctx.lineTo(StartX+Width/2,StartY-5*Scale);
- ctx.lineTo(StartX+Width/2+20*Scale,StartY-10*Scale);
- ctx.closePath();
- ctx.fill();
- }else if(v-av<0 && Math.abs((v-av)) < 0.1){
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.moveTo(StartX+Width/2-10*Scale,StartY-10*Scale);
- ctx.lineTo(StartX+Width/2+10*Scale,StartY-15*Scale);
- ctx.lineTo(StartX+Width/2+10*Scale,StartY-5*Scale);
- ctx.closePath();
- ctx.fill();
- }else if(v-av<0 && Math.abs((v-av)) >= 0.1){
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.moveTo(StartX+Width/2+20*Scale,StartY-15*Scale);
- ctx.lineTo(StartX+Width/2+20*Scale,StartY-5*Scale);
- ctx.lineTo(StartX+Width/2,StartY-10*Scale);
- ctx.closePath();
- ctx.fill();
- ctx.beginPath();
- ctx.moveTo(StartX+Width/2,StartY-15*Scale);
- ctx.lineTo(StartX+Width/2,StartY-5*Scale);
- ctx.lineTo(StartX+Width/2-20*Scale,StartY-10*Scale);
- ctx.closePath();
- ctx.fill();
- }
- }
- }
- draw_bar(yaw);
- draw_indicator(yaw, ayaw);
- } //end draw_hdgbar
- function draw_ah(pitch, yaw, roll){
- var canvas=document.getElementById("hor");
- var ctx=canvas.getContext("2d");
- ctx.canvas.width = window.innerWidth;
- ctx.canvas.height = window.innerHeight;
- var r = 400*Scale;
- var s = 25*Scale;
- var l = 50*Scale;
- var y = 0*Scale;
- var x = 0*Scale;
- var y = 0*Scale;
- var p = 0*Scale;
- var d = 10*Scale;
- var a = 25*Scale;
- var b = 50*Scale;
- var alph = 0;
- var bet = 0;
- var lenght = 0;
- var print = 0;
- ctx.lineCap="round";
- ctx.clearRect(CenterX-450*Scale, CenterY-450*Scale, 900*Scale, 900*Scale);
- for(i=-4;i<=4;i++){ //draw inner pitch bars 10°
- p = pitch-(Math.floor(pitch/10))*10+i*10;
- if(p<=37 && p!=0 && p >=-37){
- if((Math.floor(pitch/10))*10-i*10<0){
- ctx.strokeStyle =red;
- ctx.fillStyle =red;
- l = 100*Scale;
- ctx.lineWidth = 2*Scale;
- }else if((Math.floor(pitch/10))*10-i*10>0){
- ctx.strokeStyle =blue;
- ctx.fillStyle =blue;
- l = 100*Scale;
- ctx.lineWidth = 2*Scale;
- }else{
- var grd1=ctx.createLinearGradient(CenterX+(p*d-b)*Math.sin(-roll*Math.PI/180), CenterY+(p*d-b)*Math.cos(-roll*Math.PI/180),CenterX+(p*d+b)*Math.sin(-roll*Math.PI/180), CenterY+(p*d+b)*Math.cos(-roll*Math.PI/180));
- grd1.addColorStop(0,blue.slice(0,-3)+",0)");
- grd1.addColorStop(0.4999,blue.slice(0,-3)+",0.2)");
- grd1.addColorStop(0.5001,red.slice(0,-3)+",0.2)");
- grd1.addColorStop(1,red.slice(0,-3)+",0)");
- ctx.beginPath();
- ctx.arc(CenterX, CenterY, 399*Scale, 0, 2*Math.PI, false);
- ctx.closePath();
- ctx.fillStyle=grd1;
- ctx.fill();
- l = Math.sqrt(r*r-(p*d)*(p*d));
- ctx.strokeStyle =blue;
- ctx.lineWidth = 4*Scale;
- }
- ctx.beginPath();
- ctx.moveTo(CenterX-l*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180), CenterY+l*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180));
- ctx.lineTo(CenterX+l*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180), CenterY-l*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180));
- ctx.stroke();
- ctx.font = 14*Scale+'pt Courier New';
- ctx.lineWidth = 1*Scale;
- ctx.textAlign = 'center';
- print = (Math.floor(pitch/10))*10-i*10;
- if(print> 90){
- print+=2*(90-print);
- }
- if(print< -90){
- print+=2*(-90-print);
- }
- if(print != 0){
- ctx.fillText(print, CenterX-(l+s)*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180), CenterY+6*Scale+(l+2*d)*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180));
- ctx.strokeText(print, CenterX-(l+s)*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180), CenterY+6*Scale+(l+2*d)*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180));
- ctx.fillText(print, CenterX+(l+s)*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180), CenterY+6*Scale-(l+2*d)*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180));
- ctx.strokeText(print, CenterX+(l+s)*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180), CenterY+6*Scale-(l+2*d)*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180));
- }
- }
- }
- for(i=-5;i<=4;i++){ //draw inner pitch bars 5°
- s = 50*Scale;
- p = pitch-(Math.floor(pitch/10))*10+i*10+5;
- if(p<=38 && p!=0 && p >=-38){
- if(pitch-(i+1)*10<0){
- ctx.strokeStyle =red;
- }else{
- ctx.strokeStyle =blue;
- }
- ctx.lineWidth = 2*Scale;
- ctx.beginPath();
- ctx.moveTo(CenterX-s*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180), CenterY+s*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180));
- ctx.lineTo(CenterX+s*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180), CenterY-s*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180));
- ctx.stroke();
- }
- }
- for(i=-4;i<=4;i++){ //draw inner yaw bars 10°
- l = 50*Scale;
- y = -(yaw-(Math.floor(yaw/10))*10+i*10);
- if(y<=39 && y!=0 && y >=-39){
- ctx.strokeStyle =lblue;
- ctx.fillStyle =lblue;
- ctx.lineWidth = 2*Scale;
- ctx.beginPath();
- ctx.moveTo(CenterX-l*Math.sin(roll*Math.PI/180)+y*d*Math.cos(roll*Math.PI/180), CenterY+l*Math.cos(roll*Math.PI/180)+y*d*Math.sin(roll*Math.PI/180));
- ctx.lineTo(CenterX+l*Math.sin(roll*Math.PI/180)+y*d*Math.cos(roll*Math.PI/180), CenterY-l*Math.cos(roll*Math.PI/180)+y*d*Math.sin(roll*Math.PI/180));
- ctx.stroke();
- if((Math.floor(yaw/10))*10-i*10!=0 && y<33 && y>-33){
- ctx.font = 14*Scale+'pt Courier New';
- ctx.lineWidth = 1*Scale;
- ctx.textAlign = 'center';
- print = (Math.floor(yaw/10))*10-i*10;
- if(print> 360){
- print-= 360;
- }
- if(print< 0){
- print+=360;
- }
- ctx.fillText(print, CenterX-(l+s)*Math.sin(roll*Math.PI/180)+y*d*Math.cos(roll*Math.PI/180), CenterY+6*Scale+(l+2*d)*Math.cos(roll*Math.PI/180)+y*d*Math.sin(roll*Math.PI/180));
- ctx.strokeText(print, CenterX-(l+s)*Math.sin(roll*Math.PI/180)+y*d*Math.cos(roll*Math.PI/180), CenterY+6*Scale+(l+2*d)*Math.cos(roll*Math.PI/180)+y*d*Math.sin(roll*Math.PI/180));
- ctx.fillText(print, CenterX+(l+s)*Math.sin(roll*Math.PI/180)+y*d*Math.cos(roll*Math.PI/180), CenterY+6*Scale-(l+2*d)*Math.cos(roll*Math.PI/180)+y*d*Math.sin(roll*Math.PI/180));
- ctx.strokeText(print, CenterX+(l+s)*Math.sin(roll*Math.PI/180)+y*d*Math.cos(roll*Math.PI/180), CenterY+6*Scale-(l+2*d)*Math.cos(roll*Math.PI/180)+y*d*Math.sin(roll*Math.PI/180));
- }
- }
- }
- for(i=-5;i<=4;i++){ //draw inner yaw bars 5°
- s = 10*Scale;
- y = -(yaw-(Math.floor(yaw/10))*10+i*10+5);
- if(y<=39 && y!=0 && y >=-39){
- ctx.lineWidth = 2*Scale;
- ctx.beginPath();
- ctx.moveTo(CenterX-s*Math.sin(roll*Math.PI/180)+y*d*Math.cos(roll*Math.PI/180), CenterY+s*Math.cos(roll*Math.PI/180)+y*d*Math.sin(roll*Math.PI/180));
- ctx.lineTo(CenterX+s*Math.sin(roll*Math.PI/180)+y*d*Math.cos(roll*Math.PI/180), CenterY-s*Math.cos(roll*Math.PI/180)+y*d*Math.sin(roll*Math.PI/180));
- ctx.stroke();
- }
- }
- var grd3=ctx.createRadialGradient(CenterX,CenterY,390*Scale,CenterX,CenterY,250*Scale); //draw circular gradient to dim edge
- grd3.addColorStop(0,bg.slice(0,-3)+",0.8)");
- grd3.addColorStop(1,bg.slice(0,-3)+",0)");
- ctx.beginPath();
- ctx.arc(CenterX, CenterY, 399*Scale, 0, 2*Math.PI, false);
- ctx.closePath();
- ctx.fillStyle=grd3;
- ctx.fill();
- for(i=-4;i<=4;i++){ //draw outer pitch bars 10°
- l = 20*Scale;
- p = pitch-(Math.floor(pitch/10))*10+i*10;
- x = (r-1*Scale) - Math.sqrt(r*r-(p*d)*(p*d));
- if(p<=35 && p!=0 && p >=-35){
- if(pitch-i*10<0){
- ctx.strokeStyle =lred;
- }else{
- ctx.strokeStyle =lblue;
- }
- ctx.lineWidth = 2*Scale;
- ctx.beginPath();
- ctx.moveTo(CenterX+r*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180)-x*Math.cos(-roll*Math.PI/180), CenterY-r*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180)+x*Math.sin(-roll*Math.PI/180));
- ctx.lineTo(CenterX+r*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180)-x*Math.cos(-roll*Math.PI/180)+l*Math.cos(-roll*Math.PI/180), CenterY-r*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180)+x*Math.sin(-roll*Math.PI/180)-l*Math.sin(-roll*Math.PI/180));
- ctx.stroke();
- ctx.beginPath();
- ctx.moveTo(CenterX-r*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180)+x*Math.cos(-roll*Math.PI/180), CenterY+r*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180)-x*Math.sin(-roll*Math.PI/180));
- ctx.lineTo(CenterX-r*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180)+x*Math.cos(-roll*Math.PI/180)-l*Math.cos(-roll*Math.PI/180), CenterY+r*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180)-x*Math.sin(-roll*Math.PI/180)+l*Math.sin(-roll*Math.PI/180));
- ctx.stroke();
- }
- }
- for(i=-5;i<=4;i++){ //draw outer pitch bars 5°
- s = 10*Scale;
- p = pitch-(Math.floor(pitch/10))*10+i*10+5;
- x = (r-1*Scale) - Math.sqrt(r*r-(p*d)*(p*d));
- if(p<=35 && p!=0 && p >=-35){
- if(pitch-(i+1)*10<0){
- ctx.strokeStyle =lred;
- }else{
- ctx.strokeStyle =lblue;
- }
- ctx.lineWidth = 2*Scale;
- ctx.beginPath();
- ctx.moveTo(CenterX+r*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180)-x*Math.cos(-roll*Math.PI/180), CenterY-r*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180)+x*Math.sin(-roll*Math.PI/180));
- ctx.lineTo(CenterX+r*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180)-x*Math.cos(-roll*Math.PI/180)+s*Math.cos(-roll*Math.PI/180), CenterY-r*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180)+x*Math.sin(-roll*Math.PI/180)-s*Math.sin(-roll*Math.PI/180));
- ctx.stroke();
- ctx.beginPath();
- ctx.moveTo(CenterX-r*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180)+x*Math.cos(-roll*Math.PI/180), CenterY+r*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180)-x*Math.sin(-roll*Math.PI/180));
- ctx.lineTo(CenterX-r*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180)+x*Math.cos(-roll*Math.PI/180)-s*Math.cos(-roll*Math.PI/180), CenterY+r*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180)-x*Math.sin(-roll*Math.PI/180)+s*Math.sin(-roll*Math.PI/180));
- ctx.stroke();
- }
- }
- if(pitch>=0){ //draw pitch degree dots
- s =5*Scale;
- for(i=0;i<=pitch;i++){
- p = pitch-i;
- x = r-s - Math.sqrt(r*r-(p*d)*(p*d));
- if(p<=35 && p!=0 && p >=-35){
- ctx.fillStyle =lblue;
- ctx.fillRect(CenterX-1*Scale+r*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180)-x*Math.cos(-roll*Math.PI/180),CenterY-1*Scale-r*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180)+x*Math.sin(-roll*Math.PI/180),2*Scale,2*Scale);
- }
- }
- }else{
- s =5*Scale;
- for(i=1;i<=Math.abs(pitch);i++){
- p = pitch+i;
- x = r-s - Math.sqrt(r*r-(p*d)*(p*d));
- if(p<=35 && p!=0 && p >=-35){
- ctx.fillStyle =lred;
- ctx.fillRect(CenterX-1*Scale+r*Math.cos(-roll*Math.PI/180)+p*d*Math.sin(-roll*Math.PI/180)-x*Math.cos(-roll*Math.PI/180),CenterY-1*Scale-r*Math.sin(-roll*Math.PI/180)+p*d*Math.cos(-roll*Math.PI/180)+x*Math.sin(-roll*Math.PI/180),2*Scale,2*Scale);
- }
- }
- }
- if(pitch>=0 && pitch <10){ //calculate position of pitch number based on text lenght
- lenght=24*Scale;
- }else if(pitch>=10 && pitch <100){
- lenght=30*Scale;
- }else if(pitch>-10 && pitch <0){
- lenght=30*Scale;
- }else{
- lenght=36*Scale;
- }
- if(pitch>=0){ //draw pitch number, red when neg, blue when pos
- ctx.fillStyle = blue;
- ctx.strokeStyle = blue;
- }else{
- ctx.fillStyle = red;
- ctx.strokeStyle = red;
- }
- ctx.fillText(pitch.toFixed(1)+"°", CenterX+(Math.cos(roll*Math.PI/180)*(420*Scale+lenght)),CenterY+6*Scale+(Math.sin(roll*Math.PI/180)*430*Scale));
- ctx.strokeText(pitch.toFixed(1)+"°", CenterX+(Math.cos(roll*Math.PI/180)*(420*Scale+lenght)),CenterY+6*Scale+(Math.sin(roll*Math.PI/180)*430*Scale));
- ctx.lineWidth = 4*Scale; //draw wing level
- ctx.strokeStyle = blue;
- ctx.beginPath();
- ctx.moveTo(CenterX+370*Scale*Math.cos(roll*Math.PI/180), CenterY+370*Scale*Math.sin(roll*Math.PI/180));
- ctx.lineTo(CenterX+420*Scale*Math.cos(roll*Math.PI/180), CenterY+420*Scale*Math.sin(roll*Math.PI/180));
- ctx.stroke();
- ctx.beginPath();
- ctx.moveTo(CenterX-370*Scale*Math.cos(roll*Math.PI/180), CenterY-370*Scale*Math.sin(roll*Math.PI/180));
- ctx.lineTo(CenterX-420*Scale*Math.cos(roll*Math.PI/180), CenterY-420*Scale*Math.sin(roll*Math.PI/180));
- ctx.stroke();
- ctx.font = 14*Scale+'pt Courier New'; //draw roll indicator
- ctx.lineWidth = 2*Scale;
- ctx.fillStyle = blue;
- ctx.strokeStyle = blue;
- ctx.textAlign = 'center';
- print = roll;
- if(print>=0 && print <10){ //calculate position of roll number based on text lenght
- lenght=24*Scale;
- }else if(print>=10 && print <100){
- lenght=30*Scale;
- }else if(print>-10 && print <0){
- lenght=30*Scale;
- }else if(print>=100){
- lenght=36*Scale;
- }else if(print>-100 && print <=-10){
- lenght=36*Scale;
- }else{
- lenght=42*Scale;
- }
- if(roll<-4 || roll>4){ //draw roll number except close to 0, 90, 180, -90
- if(roll<85 || roll>95){
- if(roll>-85 || roll<-95){
- if(roll<176){
- if(roll>-176){
- ctx.fillText(print.toFixed(1)+"°", CenterX-(Math.cos(roll*Math.PI/180))*(360*Scale-lenght), CenterY+6*Scale-(Math.sin(roll*Math.PI/180))*350*Scale);
- ctx.strokeText(print.toFixed(1)+"°", CenterX-(Math.cos(roll*Math.PI/180))*(360*Scale-lenght), CenterY+6*Scale-(Math.sin(roll*Math.PI/180))*350*Scale);
- }
- }
- }
- }
- }
- if(roll>0){ //draw roll degree dots
- s =5*Scale;
- for(i=0;i<roll;i++){
- ctx.fillStyle = lblue;
- ctx.fillRect(CenterX-1*Scale-(Math.cos(i*Math.PI/180))*(r-s), CenterY-1*Scale-(Math.sin(i*Math.PI/180))*(r-s), 2*Scale, 2*Scale);
- }
- }else if(roll<0){
- s =5*Scale;
- for(i=0;i<-roll;i++){
- ctx.fillStyle = lblue;
- ctx.fillRect(CenterX-1*Scale-(Math.cos(-i*Math.PI/180))*(r-s), CenterY-1*Scale-(Math.sin(-i*Math.PI/180))*(r-s), 2*Scale, 2*Scale);
- }
- }else{
- }
- ctx.strokeStyle = lblue;
- for(i=0; i<36;i++){ //draw roll marks 0, 90, 180, -90
- ctx.beginPath();
- if(i==0 || i==9 || i==18 || i==27){
- ctx.moveTo(CenterX-(r-1*Scale)*Math.cos(i*10*Math.PI/180), CenterY-(r-1*Scale)*Math.sin(i*10*Math.PI/180));
- ctx.lineTo(CenterX-(r-30*Scale)*Math.cos(i*10*Math.PI/180), CenterY-(r-30*Scale)*Math.sin(i*10*Math.PI/180));
- }else{
- ctx.moveTo(CenterX-(r-1*Scale)*Math.cos(i*10*Math.PI/180), CenterY-(r-1*Scale)*Math.sin(i*10*Math.PI/180));
- ctx.lineTo(CenterX-(r-20*Scale)*Math.cos(i*10*Math.PI/180), CenterY-(r-20*Scale)*Math.sin(i*10*Math.PI/180));
- }
- ctx.stroke();
- }
- for(i=0; i<36;i++){ //draw roll marks 10°
- ctx.beginPath();
- ctx.moveTo(CenterX-(r-1*Scale)*Math.cos((i+0.5)*10*Math.PI/180), CenterY-(r-1*Scale)*Math.sin((i+0.5)*10*Math.PI/180));
- ctx.lineTo(CenterX-(r-10*Scale)*Math.cos((i+0.5)*10*Math.PI/180), CenterY-(r-10*Scale)*Math.sin((i+0.5)*10*Math.PI/180));
- ctx.stroke();
- }
- for(i=-1; i<3;i++){ //draw roll text 0, 90, 180, -90
- ctx.font = 14*Scale+'pt Courier New';
- ctx.fillStyle = lblue;
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = lblue;
- ctx.textAlign = 'center';
- ctx.fillText(i*90+"°", CenterX-(r-50*Scale)*Math.cos(i*90*Math.PI/180), CenterY+6*Scale-(r-44*Scale)*Math.sin(i*90*Math.PI/180));
- ctx.strokeText(i*90+"°", CenterX-(r-50*Scale)*Math.cos(i*90*Math.PI/180), CenterY+6*Scale-(r-44*Scale)*Math.sin(i*90*Math.PI/180));
- }
- ctx.lineWidth = 2*Scale; //draw outer ring
- ctx.strokeStyle = blue;
- ctx.beginPath();
- ctx.arc(CenterX, CenterY, 400*Scale, 0, 2 * Math.PI, false);
- ctx.stroke();
- for(i=0;i<=3;i++){ //draw center indicator
- ctx.beginPath();
- ctx.moveTo(CenterX,CenterY);
- ctx.lineTo(CenterX-60*Scale*Math.cos(i*0.5*Math.PI)+4*Math.sin(i*0.5*Math.PI),CenterY-60*Scale*Math.sin(i*0.5*Math.PI)+4*Math.cos(i*0.5*Math.PI));
- ctx.lineTo(CenterX-60*Scale*Math.cos(i*0.5*Math.PI)-4*Math.sin(i*0.5*Math.PI),CenterY-60*Scale*Math.sin(i*0.5*Math.PI)-4*Math.cos(i*0.5*Math.PI));
- ctx.closePath();
- ctx.fillStyle=white.slice(0,-3)+",0.25)";
- ctx.fill();
- } //end draw_center
- if(Math.abs(SpdHor)>0.01 || Math.abs(SpdVert)>0.01){ //draw pro and retrograde marker when moving
- draw_prograde(Pitch, Yaw, Roll, PPitch, PYaw);
- draw_retro(Pitch, Yaw, Roll, PPitch, PYaw);
- }
- if(Tar!="No Target Selected."){ //draw target marker when selected !!NOT IMPLEMENTED!!
- //draw_target(Pitch, Yaw, Roll, TPitch, TYaw, TDist);
- //draw_antitarget(Pitch, Yaw, Roll, TPitch, TYaw, TDist);
- }
- function draw_prograde(pitch, yaw, roll, ppitch, pyaw){ //draw prograde marker
- var dyaw = 0;
- var droll = 0;
- var dpitch = 0;
- PYaw = pyaw;
- PRoll = 0;
- PPitch = ppitch;
- dyaw = yaw - PYaw;
- droll = roll - PRoll; //calculate angle difference
- dpitch = pitch - PPitch;
- if(dpitch<-90){
- dpitch+=180;
- }
- var r = 320*Scale;
- var x = 0;
- var y = 0;
- var l = 40*Scale;
- var k = 10*Scale;
- var d = 10*Scale;
- var rad = 60*Scale;
- if(Math.sqrt(dpitch*dpitch+dyaw*dyaw)<32){ //draw big or small marker
- rad = 30*Scale; //draw big marker when in view
- x = CenterX-dpitch*d*Math.sin(droll*Math.PI/180)-dyaw*d*Math.cos(droll*Math.PI/180);
- y = CenterY+dpitch*d*Math.cos(droll*Math.PI/180)-dyaw*d*Math.sin(droll*Math.PI/180);
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = white;
- ctx.fillStyle = white;
- ctx.beginPath();
- ctx.arc(x, y, rad, 0, 2 * Math.PI, false);
- ctx.stroke();
- for(i=0;i<=3;i++){
- ctx.beginPath();
- ctx.moveTo(x-(rad+5*Scale)*Math.cos(i*90*Math.PI/180), y-(rad+5*Scale)*Math.sin(i*90*Math.PI/180));
- ctx.lineTo(x-(rad-5*Scale)*Math.cos(i*90*Math.PI/180), y-(rad-5*Scale)*Math.sin(i*90*Math.PI/180));
- ctx.stroke();
- }
- ctx.fillRect(x-1*Scale, y-1*i*Scale, 2*Scale, 2*Scale);
- }else if(Math.abs(dpitch)<=95 && Math.abs(dyaw)<=95){ //draw small marker and arrow when out of view
- rad = 10*Scale;
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = white;
- ctx.fillStyle = white;
- x = calc_x(r, 0, 0);
- y = calc_y(r, 0, 0);
- ctx.beginPath();
- ctx.arc(x, y, rad, 0, 2 * Math.PI, false);
- ctx.stroke();
- for(i=0;i<=3;i++){
- ctx.beginPath();
- ctx.moveTo(x-(rad+3*Scale)*Math.cos(i*90*Math.PI/180), y-(rad+3*Scale)*Math.sin(i*90*Math.PI/180));
- ctx.lineTo(x-(rad-3*Scale)*Math.cos(i*90*Math.PI/180), y-(rad-3*Scale)*Math.sin(i*90*Math.PI/180));
- ctx.stroke();
- ctx.fillRect(x-1*Scale, y-1*Scale, Scale, Scale);
- }
- ctx.beginPath();
- x = calc_x(r+70*Scale, 0, 0);
- y = calc_y(r+70*Scale, 0, 0);
- ctx.moveTo(x,y);
- x = calc_x(r+70*Scale, 50*Scale, 1);
- y = calc_y(r+70*Scale, 50*Scale, 1);
- ctx.lineTo(x,y);
- x = calc_x(r+70*Scale, 50*Scale, -1);
- y = calc_y(r+70*Scale, 50*Scale, -1);
- ctx.lineTo(x,y);
- ctx.closePath();
- ctx.fill();
- function calc_x(rad, t, w){ //calculate x-position
- var x = 0;
- var a = 0;
- var b = 0;
- a = ((rad-t)*dyaw)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- b = ((rad-t)*dpitch)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- x = CenterX-(a*Math.cos((w+droll)*Math.PI/180)+(b*Math.sin((w+droll)*Math.PI/180)));
- return x;
- }
- function calc_y(rad, t, w){ //calculate y-position
- var y = 0;
- var a = 0;
- var b = 0;
- a = ((rad-t)*dyaw)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- b = ((rad-t)*dpitch)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- y = CenterY+(b*Math.cos((w+droll)*Math.PI/180)-(a*Math.sin((w+droll)*Math.PI/180)));
- return y;
- }
- }
- } //end draw_pro
- function draw_retro(pitch, yaw, roll, ppitch, pyaw){ //draw retrograde marker
- var dyaw = 0;
- var droll = 0;
- var dpitch = 0;
- var rpitch = 0;
- var rroll = 0;
- var ryaw = 0;
- var d = 10*Scale;
- PYaw = pyaw;
- PRoll = 0;
- PPitch = ppitch;
- RPitch = -PPitch;
- RRoll = PRoll;
- RYaw = PYaw +180;
- if(RYaw > 360){
- RYaw-=360;
- }
- dyaw = yaw - RYaw; //calculate angle difference
- droll = roll - RRoll;
- dpitch = pitch - RPitch;
- var r = 320*Scale;
- var a = 0;
- var b = 0;
- if(Math.sqrt(dpitch*dpitch+dyaw*dyaw)<32){ //draw big or small marker
- rad = 30*Scale; //draw big marker when in view
- x = CenterX-dpitch*d*Math.sin(droll*Math.PI/180)-dyaw*d*Math.cos(droll*Math.PI/180);
- y = CenterY+dpitch*d*Math.cos(droll*Math.PI/180)-dyaw*d*Math.sin(droll*Math.PI/180);
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = white;
- ctx.fillStyle = white;
- ctx.beginPath();
- ctx.arc(x, y, rad, 0, 2 * Math.PI, false);
- ctx.stroke();
- for(i=0;i<=1;i++){
- ctx.moveTo(x-(rad+5*Scale)*Math.cos((i+0.5)*90*Math.PI/180), y+(rad+5*Scale)*Math.sin((i+0.5)*90*Math.PI/180));
- ctx.lineTo(x+(rad+5*Scale)*Math.cos((i+0.5)*90*Math.PI/180), y-(rad+5*Scale)*Math.sin((i+0.5)*90*Math.PI/180));
- ctx.stroke();
- }
- }else if(Math.abs(dpitch)<=95 && Math.abs(dyaw)<=95){ //draw small marker and arrow when out of view
- x = calc_x(r, 0, 0);
- y = calc_y(r, 0, 0);
- rad = 10*Scale;
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = white;
- ctx.fillStyle = white;
- ctx.beginPath();
- ctx.arc(x, y, rad, 0, 2 * Math.PI, false);
- ctx.stroke();
- for(i=0;i<=1;i++){
- ctx.beginPath();
- ctx.moveTo(x-(rad+3*Scale)*Math.cos((i+0.5)*90*Math.PI/180), y+(rad+3*Scale)*Math.sin((i+0.5)*90*Math.PI/180));
- ctx.lineTo(x+(rad+3*Scale)*Math.cos((i+0.5)*90*Math.PI/180), y-(rad+3*Scale)*Math.sin((i+0.5)*90*Math.PI/180));
- ctx.stroke();
- }
- ctx.beginPath();
- x = calc_x(r+70*Scale, 0, 0);
- y = calc_y(r+70*Scale, 0, 0);
- ctx.moveTo(x,y);
- x = calc_x(r+70*Scale, 50*Scale, 1);
- y = calc_y(r+70*Scale, 50*Scale, 1);
- ctx.lineTo(x,y);
- x = calc_x(r+70*Scale, 50*Scale, -1);
- y = calc_y(r+70*Scale, 50*Scale, -1);
- ctx.lineTo(x,y);
- ctx.f;
- ctx.fill();
- function calc_x(rad, t, w){ //calculate x position
- var x = 0;
- var a = 0;
- var b = 0;
- a = ((rad-t)*dyaw)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- b = ((rad-t)*dpitch)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- x = CenterX-(a*Math.cos((w+droll)*Math.PI/180)+(b*Math.sin((w+droll)*Math.PI/180)));
- return x;
- }
- function calc_y(rad, t, w){ //calculate y position
- var y = 0;
- var a = 0;
- var b = 0;
- a = ((rad-t)*dyaw)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- b = ((rad-t)*dpitch)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- y = CenterY+(b*Math.cos((w+droll)*Math.PI/180)-(a*Math.sin((w+droll)*Math.PI/180)));
- return y;
- }
- }else{
- }
- } //end draw_retro
- function draw_target(pitch, yaw, roll, tpitch, tyaw, tdist){ //draw target marker
- var dyaw = 0;
- var droll = 0;
- var dpitch = 0;
- var print = 0;
- var unit ="";
- if(tdist > 9999999){ //calculate unit and exponent of distance
- exponent = 1000000;
- unit = "Mm";
- }else if(tdist>9999 && tdist <= 9999999){
- exponent = 1000;
- unit = "km";
- }else{
- exponent = 1;
- unit = "m";
- }
- print = tdist/exponent;
- PYaw = tyaw;
- PRoll = 0;
- PPitch = tpitch;
- dyaw = yaw - PYaw;
- droll = roll - PRoll; //calculate angle difference
- dpitch = pitch - PPitch;
- if(dpitch<-90){
- dpitch+=180;
- }
- var r = 320*Scale;
- var x = 0;
- var y = 0;
- var l = 40*Scale;
- var k = 10*Scale;
- var d = 10*Scale;
- var rad = 60*Scale;
- if(Math.sqrt(dpitch*dpitch+dyaw*dyaw)<32){ //draw big or small marker and distance
- rad = 30*Scale; //draw big marker and distance when in view
- x = CenterX-dpitch*d*Math.sin(droll*Math.PI/180)-dyaw*d*Math.cos(droll*Math.PI/180);
- y = CenterY+dpitch*d*Math.cos(droll*Math.PI/180)-dyaw*d*Math.sin(droll*Math.PI/180);
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = blue;
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.arc(x, y, rad, 0, 2 * Math.PI, false);
- ctx.stroke();
- for(i=0;i<=3;i++){
- ctx.moveTo(x-(rad+5*Scale)*Math.cos(i*90*Math.PI/180), y-(rad+5*Scale)*Math.sin(i*90*Math.PI/180));
- ctx.lineTo(x-(rad-5*Scale)*Math.cos(i*90*Math.PI/180), y-(rad-5*Scale)*Math.sin(i*90*Math.PI/180));
- ctx.stroke();
- }
- ctx.fillRect(x-1*Scale, y-1*i*Scale, 2*Scale, 2*Scale);
- ctx.font = 14*Scale+'pt Courier New';
- ctx.fillStyle = blue;
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = blue;
- ctx.textAlign = 'center';
- ctx.fillText(print.toFixed(1)+unit, CenterX-dpitch*10*Math.sin(droll*Math.PI/180)-dyaw*10*Math.cos(droll*Math.PI/180),CenterY+40+dpitch*10*Math.cos(droll*Math.PI/180)-dyaw*10*Math.sin(droll*Math.PI/180));
- ctx.strokeText(print.toFixed(1)+unit, CenterX-dpitch*10*Math.sin(droll*Math.PI/180)-dyaw*10*Math.cos(droll*Math.PI/180),CenterY+40+dpitch*10*Math.cos(droll*Math.PI/180)-dyaw*10*Math.sin(droll*Math.PI/180));
- }else if(Math.abs(dpitch)<=95 && Math.abs(dyaw)<=95){ //draw small marker, arrow and distance when out of view
- rad = 10*Scale;
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = blue;
- ctx.fillStyle = blue;
- x = calc_x(r, 0, 0);
- y = calc_y(r, 0, 0);
- ctx.beginPath();
- ctx.arc(x, y, rad, 0, 2 * Math.PI, false);
- ctx.stroke();
- for(i=0;i<=3;i++){
- ctx.beginPath();
- ctx.moveTo(x-(rad+5*Scale)*Math.cos(i*90*Math.PI/180), y-(rad+5*Scale)*Math.sin(i*90*Math.PI/180));
- ctx.lineTo(x-(rad-5*Scale)*Math.cos(i*90*Math.PI/180), y-(rad-5*Scale)*Math.sin(i*90*Math.PI/180));
- ctx.stroke();
- ctx.fillRect(x-1*Scale, y-1*Scale, Scale, Scale);
- }
- ctx.beginPath();
- x = calc_x(r+70*Scale, 0, 0);
- y = calc_y(r+70*Scale, 0, 0);
- ctx.moveTo(x,y);
- x = calc_x(r+70*Scale, 30, 1);
- y = calc_y(r+70*Scale, 30, 1);
- ctx.lineTo(x,y);
- x = calc_x(r+70*Scale, 30, -1);
- y = calc_y(r+70*Scale, 30, -1);
- ctx.lineTo(x,y);
- ctx.closePath();
- ctx.fill();
- ctx.font = 14*Scale+'pt Courier New';
- ctx.fillStyle = blue;
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = blue;
- ctx.textAlign = 'center';
- x = calc_x(r-60*Scale, 0, 0);
- y = calc_y(r-40*Scale, 0, 0);
- ctx.fillText(print.toFixed(1)+unit, x, y);
- ctx.strokeText(print.toFixed(1)+unit, x, y);
- function calc_x(rad, t, w){ //calculate x position
- var x = 0;
- var a = 0;
- var b = 0;
- a = ((rad-t)*dyaw)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- b = ((rad-t)*dpitch)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- x = CenterX-(a*Math.cos((w+droll)*Math.PI/180)+(b*Math.sin((w+droll)*Math.PI/180)));
- return x;
- }
- function calc_y(rad, t, w){ //calculate y position
- var y = 0;
- var a = 0;
- var b = 0;
- a = ((rad-t)*dyaw)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- b = ((rad-t)*dpitch)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- y = CenterY+(b*Math.cos((w+droll)*Math.PI/180)-(a*Math.sin((w+droll)*Math.PI/180)));
- return y;
- }
- }
- } //end draw_target
- function draw_antitarget(pitch, yaw, roll, tpitch, tyaw, tdist){ //draw antitarget marker
- var dyaw = 0;
- var droll = 0;
- var dpitch = 0;
- var rpitch = 0;
- var rroll = 0;
- var ryaw = 0;
- var d = 10*Scale;
- var print = 0;
- var unit = "";
- if(tdist > 9999999){ //calculate unit and exponent of distance
- exponent = 1000000;
- unit = "Mm";
- }else if(tdist>9999 && tdist <= 9999999){
- exponent = 1000;
- unit = "km";
- }else{
- exponent = 1;
- unit = "m";
- }
- print = tdist/exponent
- PYaw = tyaw;
- PRoll = 0;
- PPitch = tpitch;
- RPitch = -PPitch;
- RRoll = PRoll;
- RYaw = PYaw +180;
- if(RYaw > 360){
- RYaw-=360;
- }
- dyaw = yaw - RYaw; //calculate angle difference
- droll = roll - RRoll;
- dpitch = pitch - RPitch;
- var r = 320*Scale;
- var a = 0;
- var b = 0;
- if(Math.sqrt(dpitch*dpitch+dyaw*dyaw)<32){ //draw big or small marker and distance
- rad = 30*Scale; //draw big marker and distance when in view
- x = CenterX-dpitch*d*Math.sin(droll*Math.PI/180)-dyaw*d*Math.cos(droll*Math.PI/180);
- y = CenterY+dpitch*d*Math.cos(droll*Math.PI/180)-dyaw*d*Math.sin(droll*Math.PI/180);
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle =blue;
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.arc(x, y, rad, 0, 2 * Math.PI, false);
- ctx.stroke();
- for(i=0;i<=1;i++){
- ctx.moveTo(x-(rad+5*Scale)*Math.cos((i+0.5)*90*Math.PI/180), y+(rad+5*Scale)*Math.sin((i+0.5)*90*Math.PI/180));
- ctx.lineTo(x+(rad+5*Scale)*Math.cos((i+0.5)*90*Math.PI/180), y-(rad+5*Scale)*Math.sin((i+0.5)*90*Math.PI/180));
- ctx.stroke();
- }
- ctx.font = 14*Scale+'pt Courier New';
- ctx.fillStyle = blue;
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = blue;
- ctx.textAlign = 'center';
- ctx.fillText(print.toFixed(1)+unit, CenterX-dpitch*10*Math.sin(droll*Math.PI/180)-dyaw*10*Math.cos(droll*Math.PI/180),CenterY+40+dpitch*10*Math.cos(droll*Math.PI/180)-dyaw*10*Math.sin(droll*Math.PI/180));
- ctx.strokeText(print.toFixed(1)+unit, CenterX-dpitch*10*Math.sin(droll*Math.PI/180)-dyaw*10*Math.cos(droll*Math.PI/180),CenterY+40+dpitch*10*Math.cos(droll*Math.PI/180)-dyaw*10*Math.sin(droll*Math.PI/180));
- }else if(Math.abs(dpitch)<=95 && Math.abs(dyaw)<=95){ //draw small marker, arrow and distance when out of view
- x = calc_x(r, 0, 0);
- y = calc_y(r, 0, 0);
- rad = 10*Scale;
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = blue;
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.arc(x, y, rad, 0, 2 * Math.PI, false);
- ctx.stroke();
- for(i=0;i<=1;i++){
- ctx.moveTo(x-(rad+5*Scale)*Math.cos((i+0.5)*90*Math.PI/180), y+(rad+5*Scale)*Math.sin((i+0.5)*90*Math.PI/180));
- ctx.lineTo(x+(rad+5*Scale)*Math.cos((i+0.5)*90*Math.PI/180), y-(rad+5*Scale)*Math.sin((i+0.5)*90*Math.PI/180));
- ctx.stroke();
- }
- ctx.beginPath();
- x = calc_x(r+70*Scale, 0, 0);
- y = calc_y(r+70*Scale, 0, 0);
- ctx.moveTo(x,y);
- x = calc_x(r+70*Scale, 30, 1);
- y = calc_y(r+70*Scale, 30, 1);
- ctx.lineTo(x,y);
- x = calc_x(r+70*Scale, 30, -1);
- y = calc_y(r+70*Scale, 30, -1);
- ctx.lineTo(x,y);
- ctx.closePath();
- ctx.fill();
- ctx.font = 14*Scale+'pt Courier New';
- ctx.fillStyle = blue;
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = blue;
- ctx.textAlign = 'center';
- x = calc_x(r-60*Scale, 0, 0);
- y = calc_y(r-40*Scale, 0, 0);
- ctx.fillText(print.toFixed(1)+unit, x, y);
- ctx.strokeText(print.toFixed(1)+unit, x, y);
- function calc_x(rad, t, w){ //calculate x position
- var x = 0;
- var a = 0;
- var b = 0;
- a = ((rad-t)*dyaw)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- b = ((rad-t)*dpitch)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- x = CenterX-(a*Math.cos((w+droll)*Math.PI/180)+(b*Math.sin((w+droll)*Math.PI/180)));
- return x;
- }
- function calc_y(rad, t, w){ //calculate y position
- var y = 0;
- var a = 0;
- var b = 0;
- a = ((rad-t)*dyaw)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- b = ((rad-t)*dpitch)/Math.sqrt(dpitch*dpitch+dyaw*dyaw);
- y = CenterY+(b*Math.cos((w+droll)*Math.PI/180)-(a*Math.sin((w+droll)*Math.PI/180)));
- return y;
- }
- }
- } //end draw_antitarget
- } //end draw_ah
- function draw_buttons(){
- var canvas=document.getElementById("btn");
- var ctx=canvas.getContext("2d");
- ctx.canvas.width = window.innerWidth;
- ctx.canvas.height = window.innerHeight;
- var BtnX = 1482*Scale;
- var BtnY = 50*Scale;
- var BWidth = 116*Scale;
- var BHeight = 50*Scale;
- var BDiffs = 10*Scale;
- var BDiffl = 20*Scale;
- var BDiffxs = 7.6*Scale;
- var BDiffxl = 50*Scale;
- var TDiff = 32*Scale;
- var SWidth = 800*Scale;
- var SHeight = 476*Scale;
- var BX = new Array(BtnX, BtnX+BWidth+BDiffs, BtnX+2*BWidth+2*BDiffs, BtnX+92*Scale, BtnX+276*Scale);
- var BY = 0;
- var SX = 1920*Scale/2-SWidth/2;
- var SY = 1080*Scale/2-SHeight/2;
- var print = "";
- var time = 0;
- function reset(){ //timer to prevent multiple click events and to make switches light up shortly
- rst = true;
- btn = false;
- ag = 0;
- }
- function Button(x, y, w, h, type, t, st){ //defines how each button gets drawn and what happens when clicked
- var delty = 0;
- var deltx = 0;
- canvas.addEventListener('click', doMouseDown, false);
- //ctx.clearRect(x,y,w,h);
- draw();
- function draw(){ //draw styles for each button
- switch(type){ //button background
- case "IndOn":
- ctx.fillStyle=blue;
- break;
- case "IndOff":
- ctx.fillStyle=blue.slice(0,-3)+",0.2)";
- break;
- case "Warn":
- ctx.fillStyle=lred;
- break;
- case "AlarmOn":
- ctx.fillStyle=red;
- break;
- case "AlarmOff":
- ctx.fillStyle=red.slice(0,-3)+",0.2)";
- break;
- case "ButtonOn":
- ctx.fillStyle=blue;
- break;
- case "ButtonOff":
- ctx.fillStyle=blue.slice(0,-3)+",0.2)";
- break;
- case "IP":
- ctx.fillStyle=blue;
- break;
- case "RATE":
- ctx.fillStyle=blue;
- break;
- case "C1":
- ctx.fillStyle=blue;
- break;
- case "H1":
- ctx.fillStyle=lblue;
- break;
- case "BG":
- ctx.fillStyle=bg;
- break;
- case "C2":
- ctx.fillStyle=red;
- break;
- case "H2":
- ctx.fillStyle=lred;
- break;
- case "MK":
- ctx.fillStyle=white;
- break;
- case "C1R":
- ctx.fillStyle=blue;
- break;
- case "H1R":
- ctx.fillStyle=lblue;
- break;
- case "BGR":
- ctx.fillStyle=bg;
- break;
- case "C2R":
- ctx.fillStyle=red;
- break;
- case "H2R":
- ctx.fillStyle=lred;
- break;
- case "MKR":
- ctx.fillStyle=white;
- break;
- case "TITLE +":
- ctx.fillStyle=bg;
- break;
- case "TITLE -":
- ctx.fillStyle=bg;
- break;
- case "SUBTITLE":
- ctx.fillStyle=bg;
- break;
- case "SUBTITLE +":
- ctx.fillStyle=bg;
- break;
- case "SUBTITLE -":
- ctx.fillStyle=bg;
- break;
- }
- ctx.fillRect(x,y,w,h);
- switch(type){ //button text
- case "IndOn":
- ctx.fillStyle = lblue;
- ctx.strokeStyle = lblue;
- break;
- case "IndOff":
- ctx.fillStyle = bg;
- ctx.strokeStyle = bg;
- break;
- case "Warn":
- ctx.fillStyle = bg;
- ctx.strokeStyle = bg;
- break;
- case "AlarmOn":
- ctx.fillStyle = bg;
- ctx.strokeStyle = bg;
- break;
- case "AlarmOff":
- ctx.fillStyle = bg;
- ctx.strokeStyle = bg;
- break;
- case "ButtonOn":
- ctx.fillStyle = bg;
- ctx.strokeStyle = bg;
- break;
- case "ButtonOff":
- ctx.fillStyle = bg;
- ctx.strokeStyle = bg;
- break;
- case "IP":
- ctx.fillStyle = setbg;
- ctx.strokeStyle = setbg;
- break;
- case "RATE":
- ctx.fillStyle = setbg;
- ctx.strokeStyle = setbg;
- break;
- case "C1":
- ctx.fillStyle = setbg;
- ctx.strokeStyle = setbg;
- break;
- case "H1":
- ctx.fillStyle = setbg;
- ctx.strokeStyle = setbg;
- break;
- case "BG":
- ctx.fillStyle = setbg;
- ctx.strokeStyle = setbg;
- break;
- case "C2":
- ctx.fillStyle = setbg;
- ctx.strokeStyle = setbg;
- break;
- case "H2":
- ctx.fillStyle = setbg;
- ctx.strokeStyle = setbg;
- break;
- case "MK":
- ctx.fillStyle = setbg;
- ctx.strokeStyle = setbg;
- break;
- }
- ctx.lineWidth = 1*Scale;
- if(st !="" && st !="C" && st !="R"){ //secondary text can change position of primary text, also used as a switch to change layout
- ctx.font = 22*Scale+'pt Courier New';
- ctx.textAlign = "right";
- delty = 24*Scale;
- deltx = w - 8*Scale;
- }else if(st == "C"){
- ctx.font = 24*Scale+'pt Courier New';
- ctx.textAlign = "left";
- delty = 42*Scale;
- deltx = 8*Scale;
- }else{
- ctx.font = 22*Scale+'pt Courier New';
- ctx.textAlign = "left";
- delty = 32*Scale;
- deltx = 8*Scale;
- }
- if(st !="R"){ //color reset buttons don't have text
- ctx.fillText(t, x+deltx, y+delty);
- ctx.strokeText(t, x+deltx, y+delty);
- }
- if(st !="R" && st!="C"){ //secondary text
- ctx.font = 10*Scale+'pt Courier New';
- ctx.textAlign = 'left';
- ctx.fillText(st, x+8*Scale, y+Height-8*Scale);
- }
- if(type == "CLOSE"){ //settings close button
- ctx.fillStyle = red;
- ctx.fillRect(x, y, 20*Scale, 20*Scale);
- ctx.strokeStyle = lred;
- ctx.lineWidth = 2*Scale;
- ctx.beginPath();
- ctx.moveTo(x+4*Scale, y+4*Scale);
- ctx.lineTo(x+16*Scale, y+16*Scale);
- ctx.stroke();
- ctx.beginPath();
- ctx.moveTo(x+4*Scale, y+16*Scale);
- ctx.lineTo(x+16*Scale, y+4*Scale);
- ctx.stroke();
- }
- if(type == "TITLE +"){ //clickable titles to change display mode
- ctx.clearRect(x,y,x+w,y+h);
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = red;
- ctx.fillStyle = red;
- ctx.font = 24*Scale+'pt Courier New';
- ctx.textAlign = 'left';
- ctx.fillText(t, x, y+28*Scale);
- ctx.strokeText(t, x, y+28*Scale);
- ctx.fillText("[+]", x+3*BWidth-3*BDiffs, y+28*Scale);
- ctx.strokeText("[+]", x+3*BWidth-3*BDiffs, y+28*Scale);
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = blue.slice(0,-3)+",0.2)";
- ctx.beginPath();
- ctx.moveTo(x, y+40*Scale);
- ctx.lineTo(x+3*BWidth+2*BDiffs, y+40*Scale);
- ctx.stroke();
- }
- if(type == "TITLE -"){ //clickable titles to change display mode
- ctx.clearRect(x,y,x+w,y+h);
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = red;
- ctx.fillStyle = red;
- ctx.font = 24*Scale+'pt Courier New';
- ctx.textAlign = 'left';
- ctx.fillText(t, x, y+28*Scale);
- ctx.strokeText(t, x, y+28*Scale);
- ctx.fillText("[-]", x+3*BWidth-3*BDiffs, y+28*Scale);
- ctx.strokeText("[-]", x+3*BWidth-3*BDiffs, y+28*Scale);
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = blue.slice(0,-3)+",0.2)";
- ctx.beginPath();
- ctx.moveTo(x, y+40*Scale);
- ctx.lineTo(x+3*BWidth+2*BDiffs, y+40*Scale);
- ctx.stroke();
- }
- if(type == "SUBTITLE +"){ //clickable subtitles to change display mode
- ctx.clearRect(x,y,x+w,y+h);
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = red.slice(0,-3)+",0.5)";
- ctx.fillStyle = red.slice(0,-3)+",0.5)";
- ctx.font = 20*Scale+'pt Courier New';
- ctx.textAlign = 'left';
- ctx.fillText(t, x, y+16*Scale);
- ctx.strokeText(t, x, y+16*Scale);
- ctx.fillText("[+]", x+3*BWidth-2*BDiffs, y+16*Scale);
- ctx.strokeText("[+]", x+3*BWidth-2*BDiffs, y+16*Scale);
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = blue.slice(0,-3)+",0.2)";
- ctx.beginPath();
- ctx.moveTo(x, y+28*Scale);
- ctx.lineTo(x+3*BWidth+2*BDiffs, y+28*Scale);
- ctx.stroke();
- }
- if(type == "SUBTITLE -"){ //clickable subtitles to change display mode
- ctx.clearRect(x,y,x+w,y+h);
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = red.slice(0,-3)+",0.5)";
- ctx.fillStyle = red.slice(0,-3)+",0.5)";
- ctx.font = 20*Scale+'pt Courier New';
- ctx.textAlign = 'left';
- ctx.fillText(t, x, y+16*Scale);
- ctx.strokeText(t, x, y+16*Scale);
- ctx.fillText("[-]", x+3*BWidth-2*BDiffs, y+16*Scale);
- ctx.strokeText("[-]", x+3*BWidth-2*BDiffs, y+16*Scale);
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = blue.slice(0,-3)+",0.2)";
- ctx.beginPath();
- ctx.moveTo(x, y+28*Scale);
- ctx.lineTo(x+3*BWidth+2*BDiffs, y+28*Scale);
- ctx.stroke();
- }
- if(type == "SUBTITLE"){ //nonclickable subtitle
- ctx.clearRect(x,y,x+w,y+h);
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = red.slice(0,-3)+",0.5)";
- ctx.fillStyle = red.slice(0,-3)+",0.5)";
- ctx.font = 20*Scale+'pt Courier New';
- ctx.textAlign = 'left';
- ctx.fillText(t, x, y+16*Scale);
- ctx.strokeText(t, x, y+16*Scale);
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = blue.slice(0,-3)+",0.2)";
- ctx.beginPath();
- ctx.moveTo(x, y+28*Scale);
- ctx.lineTo(x+3*BWidth+2*BDiffs, y+28*Scale);
- ctx.stroke();
- }
- }
- function doMouseDown(event){ //what happens when clicked
- var mx;
- var my;
- mx = event.clientX;
- my = event.clientY;
- if((mx >= x && my >= y) && (mx <= (x+w) && my <= (y+h))){ //click on button check
- if(set==false){ //settings menu off
- if(t == "CON"){ //show menu
- set = true;
- } //----CHANGE DISPLAY MODES----
- if(st == "ATT" && disp == 1 && rst==true){ //ATTITUDE CONTROL
- disp =2;
- }
- if(st == "SYS" && disp == 1){ //SYSTEM
- disp =3;
- }
- if(st == "STAT" && disp == 1){ //STATUS
- disp =4;
- }
- if(st == "ATT2" && disp == 2){ //MIXED DISPLAY
- disp =1;
- }
- if(st == "SYS2" && (disp == 3 || disp == 5)){ //MIXED DISPLAY
- disp =1;
- }
- if(st == "STAT2" && disp == 4){ //MIXED DISPLAY
- disp =1;
- }
- if(st == "ORB" && disp == 3){ //ORBIT MAP
- disp = 5
- }
- if(st == "ORB2" && disp == 5){ //STATUS
- disp = 3;
- }
- if(disp == 1 || disp == 2){ //----MECHJEB CONTROLS----
- if(t == "ORB"){ //ORB
- mode = 1;
- }
- if(t == "SURF"){ //SURF
- mode = 2;
- }
- if(t == "TGT"){ //TGT
- mode = 3;
- }
- if(t == "NODE"){ //NODE
- connection.send('{"run":["mj.node"]}');
- mj = 19;
- }
- if(t == "PRO"){ //PRO
- mj = 1;
- connection.send('{"run":["mj.prograde"]}');
- }
- if(t == "RET"){ //RET
- mj = 2;
- connection.send('{"run":["mj.retrograde"]}');
- }
- if(t == "NML +"){ //NML+
- mj = 3;
- connection.send('{"run":["mj.normalplus"]}');
- }
- if(t == "NML -"){ //NML-
- mj = 4;
- connection.send('{"run":["mj.normalminus"]}');
- }
- if(t == "RAD +"){ //RAD+
- mj = 5;
- connection.send('{"run":["mj.radialplus"]}');
- }
- if(t == "RAD -"){ //RAD-
- mj = 6;
- connection.send('{"run":["mj.radialminus"]}');
- }
- if(t == "PIT +"){ //PIT+
- mj = 7;
- connection.send('{"run":["mj.surface2[' + Yaw + "," + (Pitch-(-delt)) + "," + -Roll + ']}');
- }
- if(t == "PIT -"){ //PIT-
- mj = 8;
- connection.send('{"run":["mj.surface2[' + Yaw + "," + (Pitch-delt) + "," + -Roll + ']}');
- }
- if(t == "YAW +"){ //YAW+
- mj = 9;
- connection.send('{"run":["mj.surface2[' + (Yaw+delt) + "," + Pitch + "," + -Roll + ']}');
- }
- if(t == "YAW -"){ //YAW-
- mj = 10;
- connection.send('{"run":["mj.surface2[' + (Yaw-delt) + "," + Pitch + "," + -Roll + ']}');
- }
- if(t == "ROL +"){ //ROL+
- mj = 11;
- connection.send('{"run":["mj.surface2[' + Yaw + "," + Pitch + "," + -(Roll+delt) + ']}');
- }
- if(t == "ROL -"){ //ROL-
- mj = 12;
- connection.send('{"run":["mj.surface2[' + Yaw + "," + Pitch + "," + -(Roll-delt) + ']}');
- }
- if(t == "TGT +"){ //TGT+
- mj = 13;
- connection.send('{"run":["mj.targetplus"]}');
- }
- if(t == "TGT -"){ //TGT-
- mj = 14;
- connection.send('{"run":["mj.targetminus"]}');
- }
- if(t == "REL +"){ //REL+
- mj = 15;
- connection.send('{"run":["mj.relativeplus"]}');
- }
- if(t == "REL -"){ //REL-
- mj = 16;
- connection.send('{"run":["mj.relativeminus"]}');
- }
- if(t == "PAR +"){ //PAR+
- mj = 17;
- connection.send('{"run":["mj.parallelplus"]}');
- }
- if(t == "PAR -"){ //PAR-
- mj = 18;
- connection.send('{"run":["mj.parallelminus"]}');
- }
- if(t == "0.1 X"){ //0.1x
- delt = 0.1;
- }
- if(t == "1 X"){ //1x
- delt = 1;
- }
- if(t == "10 X"){ //10x
- delt = 10;
- }
- } //----SYSTEM CONTROLS----
- if(disp == 1 || disp == 3){ //----System Controls----
- if(t == "LIGHT" && rst == true){ //light
- connection.send('{"run":["f.light"]}');
- }
- if(t == "GEAR" && rst == true){ //gear
- connection.send('{"run":["f.gear"]}');
- }
- if(t == "BRAKE" && rst == true){ //brake
- connection.send('{"run":["f.brake"]}');
- }
- if(t == "RCS" && rst == true){ //rcs
- connection.send('{"run":["f.rcs"]}');
- }
- if(t == "SAS" && rst == true){ //sas
- connection.send('{"run":["f.sas"]}');
- }
- if(t == "ASS" && rst == true){ //ass
- connection.send('{"run":["mj.smartassoff"]}');
- connection.send('{"run":["f.sas"]}');
- mj = 0;
- }
- }
- if(t == "ABORT" && rst == true){ //ABORT
- connection.send('{"run":["f.abort"]}');
- ab = !ab;
- }
- if(t == "1" && btn == true){ //action group 1
- connection.send('{"run":["f.ag1"]}');
- ag = 1;
- }
- if(t == "2" && btn == true){ //action group 2
- connection.send('{"run":["f.ag2"]}');
- ag = 2;
- }
- if(t == "3" && btn == true){ //action group 3
- connection.send('{"run":["f.ag3"]}');
- ag = 3;
- }
- if(t == "4" && btn == true){ //action group 4
- connection.send('{"run":["f.ag4"]}');
- ag = 4;
- }
- if(t == "5" && btn == true){ //action group 5
- connection.send('{"run":["f.ag5"]}');
- ag = 5;
- }
- if(t == "6" && btn == true){ //action group 6
- connection.send('{"run":["f.ag6"]}');
- ag = 6;
- }
- if(t == "7" && btn == true){ //action group 7
- connection.send('{"run":["f.ag7"]}');
- ag = 7;
- }
- if(t == "8" && btn == true){ //action group 8
- connection.send('{"run":["f.ag8"]}');
- ag = 8;
- }
- if(t == "9" && btn == true){ //action group 9
- connection.send('{"run":["f.ag9"]}');
- ag = 9;
- }
- if(t == "10" && btn == true){ //action group 10
- connection.send('{"run":["f.ag10"]}');
- ag = 10;
- }
- }else{ //set == true //----SETTINGS MENU----
- if(type == "IP" && rst == true){ //ip
- IP = prompt("IP and Port (127.0.0.1:8085)", IP);
- localStorage.setItem('IP', IP);
- location.reload();
- }
- if(type == "RATE" && rst == true){ //rate
- rate = prompt("Refresh Rate in ms ", rate);
- localStorage.setItem('Rate', rate);
- location.reload();
- }
- if(type == "C1" && rst == true){ //color 1
- temp = prompt("Color 1 (255, 255, 255)", blue.slice(5,-3));
- if(check_color()!=false){
- blue = "rgba("+temp+",1)";
- localStorage.setItem('C1', temp);
- }
- }
- if(type == "C1R" && rst == true){ //reset color 1
- blue = bblue;
- localStorage.setItem('C1', blue.slice(5,-3));
- }
- if(type == "H1" && rst == true){ //highlight 1
- temp = prompt("Highlight 1 (255, 255, 255)", lblue.slice(5,-3));
- if(check_color()!=false){
- lblue = "rgba("+temp+",1)";
- localStorage.setItem('H1', temp);
- }
- }
- if(type == "H1R" && rst == true){ //reset highlight 1
- lblue = blblue;
- localStorage.setItem('H1', lblue.slice(5,-3));
- }
- if(type == "BG" && rst == true){ //background color
- temp = prompt("Background (255, 255, 255)", bg.slice(5,-3));
- if(check_color()!=false){
- bg = "rgba("+temp+",1)";
- localStorage.setItem('BG', temp);
- }
- }
- if(type == "BGR" && rst == true){ //reset background color
- bg = bbg;
- localStorage.setItem('BG', bg.slice(5,-3));
- }
- if(type == "C2" && rst == true){ //color 2
- temp = prompt("Color 2 (255, 255, 255)", red.slice(5,-3));
- if(check_color()!=false){
- red = "rgba("+temp+",1)";
- localStorage.setItem('C2', temp);
- }
- }
- if(type == "C2R" && rst == true){ //reset color 2
- red = bred;
- localStorage.setItem('C2', red.slice(5,-3));
- }
- if(type == "H2" && rst == true){ //highlight 2
- temp = prompt("Highlight 2 (255, 255, 255)", lred.slice(5,-3));
- if(check_color()!=false){
- lred = "rgba("+temp+",1)";
- localStorage.setItem('H2', temp);
- }
- }
- if(type == "H2R" && rst == true){ //reset highlight 2
- lred = blred;
- localStorage.setItem('H2', lred.slice(5,-3));
- }
- if(type == "MK" && rst == true){ //marker color
- temp = prompt("Marker (255, 255, 255)", white.slice(5,-3));
- if(check_color()!=false){
- white = "rgba("+temp+",1)";
- localStorage.setItem('MK', temp);
- }
- }
- if(type == "MKR" && rst == true){ //reset marker color
- white = bwhite;
- localStorage.setItem('MK', white.slice(5,-3));
- }
- if(type == "CLOSE"){ //close settings
- set=false;
- }
- }
- btn = true; //indicates that a button was clicked
- rst = false; //prevents recognition of dublicate click events
- timeoutID = window.setTimeout(reset, 100); //timeout of 100ms to reset
- } //end if click on button
- function check_color(){ //check if input is a valid color (rgb)
- try{ //tries to create a transparent gradient with input color,
- var test=ctx.createLinearGradient(0,0,1,1); //if color is wrong format will create error message
- test.addColorStop(0.1,blue.slice(0,-3)+",0.5)");
- test.addColorStop(1,"rgba("+temp+",0.5)");
- }
- catch(err) { //catching error message,
- alert("Color in wrong format. Change not applied."); //alerting user to prevent input of invalid colors
- return false;
- }
- }
- } //end doMouseDown
- } //end button
- if (mj !=0){ //turn on ass when ass function selected
- ass = "True";
- }else{
- ass = "False";
- }
- if (disp<1 || disp>5){ //failsafe reset to mixed display incase something goes wrong
- disp = 1;
- }
- switch(con){ //connection&settings button
- case "true":
- Button(100*Scale, 50*Scale, BWidth, BHeight, "ButtonOn", "CON", "");
- break;
- case "err":
- Button(100*Scale, 50*Scale, BWidth, BHeight, "Warn", "CON", "");
- break;
- case "false":
- Button(100*Scale, 50*Scale, BWidth, BHeight, "ButtonOff", "CON", "");
- break;
- }
- if(disp == 1){ //mixed display
- ctx.clearRect(BtnX, 0, 3*BWidth+2*BDiffs, WHeight);
- BY = BtnY;
- Button(BX[0], BY-20*Scale, 3*BWidth+2*BDiffs, 30*Scale,"TITLE +", "ATTITUDE CONTROL", "ATT");
- BY += TDiff;
- switch(mode){
- case 1:
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "ORB", "");
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "SURF", "");
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "TGT", "");
- BY +=BHeight+BDiffs+BDiffl;
- if(mj == 1){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "PRO", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "PRO", "");
- }
- if(mj == 3){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "NML +", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "NML +", "");
- }
- if(mj == 5){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "RAD +", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "RAD +", "");
- }
- BY +=BHeight+BDiffs;
- if(mj == 2){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "RET", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "RET", "");
- }
- if(mj == 4){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "NML -", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "NML -", "");
- }
- if(mj == 6){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "RAD -", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "RAD -", "");
- }
- BY +=BHeight+BDiffs;
- if(mj == 19 && btn == true){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "NODE", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "NODE", "");
- }
- break;
- case 2:
- BY = BtnY+TDiff
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "ORB", "");
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "SURF", "");
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "TGT", "");
- BY +=BHeight+BDiffs+BDiffl;
- if(mj == 7 & btn == true){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "PIT +", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "PIT +", "");
- }
- if(mj == 9 & btn == true){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "YAW +", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "YAW +", "");
- }
- if(mj == 11 & btn == true){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "ROL +", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "ROL +", "");
- }
- BY +=BHeight+BDiffs;
- if(mj == 8 & btn == true){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "PIT -", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "PIT -", "");
- }
- if(mj == 10 & btn == true){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "YAW -", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "YAW -", "");
- }
- if(mj == 12 & btn == true){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "ROL -", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "ROL -", "");
- }
- BY +=BHeight+BDiffs;
- if(delt== 0.1){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "0.1 X", "");
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "1 X", "");
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "10 X", "");
- }else if(delt == 1){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "0.1 X", "");
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "1 X", "");
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "10 X", "");
- }else if(delt == 10){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "0.1 X", "");
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "1 X", "");
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "10 X", "");
- }
- break;
- case 3:
- BY = BtnY+TDiff;
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "ORB", "");
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "SURF", "");
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "TGT", "");
- BY +=BHeight+BDiffs+BDiffl;
- if(mj == 13){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "TGT +", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "TGT +", "");
- }
- if(mj == 15){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "REL +", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "REL +", "");
- }
- if(mj == 17){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "PAR +", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "PAR +", "");
- }
- BY +=BHeight+BDiffs;
- if(mj == 14){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "TGT -", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "TGT -", "");
- }
- if(mj == 16){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "REL -", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "REL -", "");
- }
- if(mj == 18){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "PAR -", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "PAR -", "");
- }
- BY +=BHeight+BDiffs;
- if(mj == 19 && btn == true){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "NODE", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "NODE", "");
- }
- break
- }
- BY +=BHeight+BDiffxl;
- Button(BX[0], BY-20*Scale, 3*BWidth+2*BDiffs, 30*Scale,"TITLE +", "INFORMATION", "SYS");
- BY+=TDiff;
- if(atmo > 0){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", "ATMO", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"IndOff", "ATMO", "");
- }
- BY +=BHeight+BDiffs;
- if(light == "True"){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "LIGHT", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "LIGHT", "");
- }
- if(brake == "True"){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "BRAKE", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "BRAKE", "");
- }
- if(sas == "True"){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "SAS", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "SAS", "");
- }
- BY +=BHeight+BDiffs;
- if(gear == "True"){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "GEAR", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "GEAR", "");
- }
- if(rcs == "True"){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "RCS", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "RCS", "");
- }
- if(ass == "True"){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "ASS", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "ASS", "");
- };
- BY +=BHeight+BDiffxl;
- Button(BX[0], BY-20*Scale, 3*BWidth+2*BDiffs, 30*Scale,"TITLE +", "STATUS", "STAT");
- draw_sliders();
- }
- if(disp == 2){ //control display
- ctx.clearRect(BtnX, 0, 3*BWidth+2*BDiffs, WHeight);
- BY = BtnY;
- Button(BX[0], BY-20*Scale, 3*BWidth+2*BDiffs, 30*Scale,"TITLE -", "ATTITUDE CONTROL", "ATT2");
- BY +=BDiffl+BDiffl;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 30*Scale,"SUBTITLE", "VESSEL", "");
- BY +=2*BDiffl;
- Button(BX[0], BY, BWidth, BHeight,"IndOn", Pitch.toFixed(1), "PITCH");
- Button(BX[1], BY, BWidth, BHeight,"IndOn", Yaw.toFixed(1), "HEADING");
- Button(BX[2], BY, BWidth, BHeight,"IndOn", Roll.toFixed(1), "ROLL");
- BY +=BHeight+BDiffl+BDiffxs;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 30*Scale,"SUBTITLE", "PROGRADE", "");
- BY +=2*BDiffl;
- Button(BX[0], BY, BWidth, BHeight,"IndOn", PPitch.toFixed(1), "PITCH");
- Button(BX[1], BY, BWidth, BHeight,"IndOn", PYaw.toFixed(1), "HEADING");
- Button(BX[2], BY, BWidth, BHeight,"IndOn", PRoll.toFixed(1), "ROLL");
- BY += BHeight+BDiffl+BDiffxs;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 30*Scale,"SUBTITLE", "MODE", "");
- BY +=2*BDiffl;
- switch(mode){
- case 1:
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "ORB", "");
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "SURF", "");
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "TGT", "");
- break;
- case 2:
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "ORB", "");
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "SURF", "");
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "TGT", "");
- break;
- case 3:
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "ORB", "");
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "SURF", "");
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "TGT", "");
- break;
- }
- BY += BHeight+BDiffl+BDiffxs;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 30*Scale,"SUBTITLE", "ORBIT CONTROL", "");
- BY +=2*BDiffl;
- if(mj == 1){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "PRO", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "PRO", "");
- }
- if(mj == 3){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "NML +", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "NML +", "");
- }
- if(mj == 5){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "RAD +", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "RAD +", "");
- }
- BY += BHeight+ BDiffs;
- if(mj == 2){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "RET", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "RET", "");
- }
- if(mj == 4){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "NML -", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "NML -", "");
- }
- if(mj == 6){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "RAD -", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "RAD -", "");
- }
- BY += BHeight+ BDiffs;
- if(mj == 19 && btn == true){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "NODE", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "NODE", "");
- }
- BY += BHeight+BDiffl+BDiffxs;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 30*Scale,"SUBTITLE", "SURFACE CONTROL", "");
- BY +=2*BDiffl;
- if(mj == 7 & btn == true){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "PIT +", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "PIT +", "");
- }
- if(mj == 9 & btn == true){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "YAW +", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "YAW +", "");
- }
- if(mj == 11 & btn == true){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "ROL +", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "ROL +", "");
- }
- BY += BHeight+ BDiffs;
- if(mj == 8 & btn == true){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "PIT -", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "PIT -", "");
- }
- if(mj == 10 & btn == true){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "YAW -", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "YAW -", "");
- }
- if(mj == 12 & btn == true){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "ROL -", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "ROL -", "");
- }
- BY += BHeight+ BDiffs;
- if(delt==0.1){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "0.1 X", "");
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "1 X", "");
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "10 X", "");
- }else if(delt ==1){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "0.1 X", "");
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "1 X", "");
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "10 X", "");
- }else if(delt == 10){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "0.1 X", "");
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "1 X", "");
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "10 X", "");
- }
- BY += BHeight+BDiffl+BDiffxs;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 30*Scale,"SUBTITLE", "TARGET CONTROL", "");
- BY +=2*BDiffl;
- if(mj == 13){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "TGT +", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "TGT +", "");
- }
- if(mj == 15){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "REL +", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "REL +", "");
- }
- if(mj == 17){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "PAR +", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "PAR +", "");
- }
- BY += BHeight+ BDiffs;
- if(mj == 14){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "TGT -", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "TGT -", "");
- }
- if(mj == 16){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "REL -", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "REL -", "");
- }
- if(mj == 18){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "PAR -", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "PAR -", "");
- }
- }
- if(disp == 3){ //info display
- ctx.clearRect(BtnX, 0, 3*BWidth+2*BDiffs, 1080*Scale);
- BY = BtnY;
- Button(BX[0], BY-20*Scale, 3*BWidth+2*BDiffs, 30*Scale,"TITLE -", "INFORMATION", "SYS2");
- BY +=BDiffl+TDiff;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 30*Scale,"SUBTITLE", "ENVIRONMENT", "");
- BY +=2*BDiffl;
- Button(BX[0], BY, BWidth, BHeight,"IndOn", Body.toUpperCase(), "");
- if(atmo > 0){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", "ATMO", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"IndOff", "ATMO", "");
- }
- BY +=BHeight+BDiffl+BDiffs;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 30*Scale,"SUBTITLE +", "ORBIT INFO", "ORB");
- BY +=2*BDiffl;
- Button(BX[0], BY, BWidth, BHeight,"IndOn", Inc.toFixed(2), "INC (deg)");
- Button(BX[1], BY, BWidth, BHeight,"IndOn", Ecc.toFixed(4), "ECC");
- if(Per>9203328){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(Per), "PER (y)");
- }else if(Per>216000){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(Per), "PER (d)");
- }else if(Per>6000){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(Per), "PER (h)");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(Per), "PER (min)");
- }
- BY +=BHeight+BDiffs;
- Button(BX[0], BY, BWidth, BHeight,"IndOn", (TrA).toFixed(2), "TrAn (deg)");
- if(Math.abs(TTA)>9203328){
- Button(BX[1], BY, BWidth, BHeight,"IndOn", format_time(TTA), "TtoAP (y)");
- }else if(Math.abs(TTA)>216000){
- Button(BX[1], BY, BWidth, BHeight,"IndOn", format_time(TTA), "TtoAP (d)");
- }else if(Math.abs(TTA)>6000){
- Button(BX[1], BY, BWidth, BHeight,"IndOn", format_time(TTA), "TtoAP (h)");
- }else if(Math.abs(TTA)>100){
- Button(BX[1], BY, BWidth, BHeight,"IndOn", format_time(TTA), "TtoAP (min)");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"IndOn", format_time(TTA), "TtoAP (sec)");
- }
- if(Math.abs(TTP)>9203328){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(TTP), "TtoPe (y)");
- }else if(Math.abs(TTP)>216000){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(TTP), "TtoPe (d)");
- }else if(Math.abs(TTP)>6000){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(TTP), "TtoPe (h)");
- }else if(Math.abs(TTP)>100){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(TTP), "TtoPe (min)");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"IndOn", format_time(TTP), "TtoPe (sec)");
- }
- BY +=BHeight+BDiffl+BDiffs;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 30*Scale,"SUBTITLE", "SYSTEMS", "");
- BY +=2*BDiffl;
- if(light == "True"){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "LIGHT", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "LIGHT", "");
- }
- if(brake == "True"){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "BRAKE", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "BRAKE", "");
- }
- if(sas == "True"){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "SAS", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "SAS", "");
- }
- BY +=BHeight+BDiffs;
- if(gear == "True"){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "GEAR", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "GEAR", "");
- }
- if(rcs == "True"){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "RCS", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "RCS", "");
- }
- if(ass == "True"){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "ASS", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "ASS", "");
- };
- BY += BHeight+BDiffl+BDiffs;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 30*Scale,"SUBTITLE", "ACTION GROUPS", "");
- BY +=2*BDiffl;
- if(ag == 1){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "1", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "1", "");
- }
- if(ag == 2){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "2", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "2", "");
- }
- if(ag == 3){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "3", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "3", "");
- }
- BY +=BHeight+BDiffs;
- if(ag == 4){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "4", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "4", "");
- }
- if(ag == 5){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "5", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "5", "");
- }
- if(ag == 6){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "6", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "6", "");
- }
- BY +=BHeight+BDiffs;
- if(ag == 7){
- Button(BX[0], BY, BWidth, BHeight,"ButtonOn", "7", "");
- }else{
- Button(BX[0], BY, BWidth, BHeight,"ButtonOff", "7", "");
- }
- if(ag == 8){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "8", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "8", "");
- }
- if(ag == 9){
- Button(BX[2], BY, BWidth, BHeight,"ButtonOn", "9", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"ButtonOff", "9", "");
- }
- BY +=BHeight+BDiffs;
- if(ag == 10){
- Button(BX[1], BY, BWidth, BHeight,"ButtonOn", "10", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"ButtonOff", "10", "");
- }
- BY += BHeight+BDiffl+BDiffs;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 30*Scale,"SUBTITLE", "ABORT", "");
- BY +=2*BDiffl;
- BY +=BHeight+BDiffs;
- if(ab == false){
- Button(BX[1], BY, BWidth, BHeight,"AlarmOff", "ABORT", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"AlarmOn", "ABORT", "");
- }
- }
- if(disp == 4){ //status display
- ctx.clearRect(BtnX, 0, 3*BWidth+2*BDiffs, 1080*Scale);
- BY = BtnY;
- Button(BX[0], BY-20*Scale, 3*BWidth+2*BDiffs, 30*Scale,"TITLE -", "STATUS", "STAT2");
- BY +=+TDiff;
- draw_dial_r_pm(BX[3],BY, (charge_r-charge)/(rate/1000), "CHARGE");
- draw_dial_r_p_10(BX[4],BY, intake, intake_max, "AIR");
- BY +=196*Scale;
- draw_dial_r_p_100(BX[3],BY, (lf_s_r-lf_s)/(rate/1000), lf_s_max, "LF");
- draw_dial_r_p_100(BX[4],BY, (ox_s_r-ox_s)/(rate/1000), ox_s_max, "OX");
- BY +=196*Scale;
- draw_dial_r_p_10(BX[3],BY, (mono_r-mono)/(rate/1000), mono_max, "MONO");
- draw_dial_r_p_100(BX[4],BY, (sf_s_r-sf_s)/(rate/1000), sf_s_max, "SOLID");
- draw_sliders();
- }
- if(disp == 5){ //info display
- ctx.clearRect(BtnX, 0, 3*BWidth+2*BDiffs, 1080*Scale);
- BY = BtnY;
- Button(BX[0], BY-20*Scale, 3*BWidth+2*BDiffs, 40*Scale,"TITLE -", "INFORMATION", "SYS2");
- BY +=BDiffl+TDiff;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 40*Scale,"SUBTITLE", "ENVIRONMENT", "");
- BY +=2*BDiffl;
- Button(BX[0], BY, BWidth, BHeight,"IndOn", Body.toUpperCase(), "");
- if(atmo > 0){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", "ATMO", "");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"IndOff", "ATMO", "");
- }
- BY +=BHeight+BDiffl+BDiffs;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 40*Scale,"SUBTITLE -", "ORBIT INFO", "ORB2");
- BY +=2*BDiffl;
- Button(BX[0], BY, BWidth, BHeight,"IndOn", Inc.toFixed(2), "INC (deg)");
- Button(BX[1], BY, BWidth, BHeight,"IndOn", Ecc.toFixed(4), "ECC");
- if(Per>9203328){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(Per), "PER (y)");
- }else if(Per>216000){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(Per), "PER (d)");
- }else if(Per>6000){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(Per), "PER (h)");
- }else{
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(Per), "PER (min)");
- }
- BY +=BHeight+BDiffs;
- Button(BX[0], BY, BWidth, BHeight,"IndOn", (TrA).toFixed(2), "TrAn (deg)");
- if(Math.abs(TTA)>9203328){
- Button(BX[1], BY, BWidth, BHeight,"IndOn", format_time(TTA), "TtoAP (y)");
- }else if(Math.abs(TTA)>216000){
- Button(BX[1], BY, BWidth, BHeight,"IndOn", format_time(TTA), "TtoAP (d)");
- }else if(Math.abs(TTA)>6000){
- Button(BX[1], BY, BWidth, BHeight,"IndOn", format_time(TTA), "TtoAP (h)");
- }else if(Math.abs(TTA)>100){
- Button(BX[1], BY, BWidth, BHeight,"IndOn", format_time(TTA), "TtoAP (min)");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"IndOn", format_time(TTA), "TtoAP (sec)");
- }
- if(Math.abs(TTP)>9203328){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(TTP), "TtoPe (y)");
- }else if(Math.abs(TTP)>216000){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(TTP), "TtoPe (d)");
- }else if(Math.abs(TTP)>6000){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(TTP), "TtoPe (h)");
- }else if(Math.abs(TTP)>100){
- Button(BX[2], BY, BWidth, BHeight,"IndOn", format_time(TTP), "TtoPe (min)");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"IndOn", format_time(TTP), "TtoPe (sec)");
- }
- BY +=BHeight+BDiffl+BDiffs;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 40*Scale,"SUBTITLE", "MAP", "");
- BY +=2*BDiffl;
- draw_orbit(BX[0]+184*Scale, BY+220*Scale);
- BY = 882*Scale;
- Button(BX[0], BY, 3*BWidth+2*BDiffs, 40*Scale,"SUBTITLE", "ABORT", "");
- BY +=2*BDiffl;
- BY +=BHeight+BDiffs;
- if(ab == false){
- Button(BX[1], BY, BWidth, BHeight,"AlarmOff", "ABORT", "");
- }else{
- Button(BX[1], BY, BWidth, BHeight,"AlarmOn", "ABORT", "");
- }
- }
- function format_time(t){
- var time = 0;
- var diff = 0;
- var diff2 = 0;
- if(Math.abs(t)>9203328){ //years
- diff = 9203328;
- diff2 = 21600;
- }else if(Math.abs(t)>21600){ //days
- diff = 21600;
- diff2 =3600;
- }else if(Math.abs(t)>6000){ //hours
- diff = 3600;
- diff2 = 60;
- }else if(Math.abs(t)>100){ //minutes
- diff = 60;
- diff2 = 1;
- }else{ //seconds
- diff = 1;
- diff = 1;
- return t.toFixed(0);
- }
- time = t/diff;
- if(Math.floor((t-Math.floor(time)*diff)/diff2)<10){
- return Math.floor(time)+":0"+(Math.floor((t-Math.floor(time)*diff)/diff2));
- }else{
- return Math.floor(time)+":"+(Math.floor((t-Math.floor(time)*diff)/diff2));
- }
- }
- function draw_orbit(x,y){
- var radius = 0;
- var a = 0;
- var SC = 0;
- var m = 0.1;
- var f = (PE/1000+radius)*2;
- switch(Body){
- case "Sun":
- radius = 261600000;
- atmo = 0;
- break;
- case "Moho":
- radius = 250000;
- atmo = 0;
- break;
- case "Eve":
- radius = 700000;
- atmo = 96708.574;
- break;
- case "Gilly":
- radius = 13000;
- atmo = 0;
- break;
- case "Kerbin":
- radius = 600000;
- atmo = 69077.553;
- break;
- case "Mun":
- radius = 200000;
- atmo = 0;
- break;
- case "Minmus":
- radius = 60000;
- atmo = 0;
- break;
- case "Duna":
- radius = 320000;
- atmo = 41446.532 ;
- break;
- case "Ike":
- radius = 130000;
- atmo = 0;
- break;
- case "Dres":
- radius = 138000;
- atmo = 0;
- break;
- case "Jool":
- radius = 6000000;
- atmo = 138155.11;
- break;
- case "Laythe":
- radius = 500000;
- atmo = 55262.042 ;
- break;
- case "Vall":
- radius = 300000;
- atmo = 0;
- break;
- case "Tylo":
- radius = 600000;
- atmo = 0;
- break;
- case "Bop":
- radius = 65000;
- atmo = 0;
- break;
- case "Pol":
- radius = 44000;
- atmo = 0;
- break;
- case "Eeloo":
- radius = 210000;
- atmo = 0;
- break;
- }
- if(Ecc<1){
- SC = radius/((AP+radius))*(140/radius)*Scale;
- }else{
- SC = radius/((PE+radius))*(50/radius)*Scale;
- }
- ctx.strokeStyle = blue;
- if(atmo>0){
- ctx.lineWidth = 0.5*Scale; //draw atmosphere
- ctx.fillStyle = blue.slice(0,-3)+",0.25)";
- ctx.beginPath();
- ctx.arc(x, y, (radius+atmo)*SC, 0, 2 * Math.PI, false);
- ctx.closePath();
- ctx.fill();
- }
- ctx.strokeStyle = lblue;
- ctx.fillStyle = lblue;
- ctx.font = 16*Scale+'pt Courier New';
- ctx.textAlign = 'center';
- ctx.lineWidth = 2*Scale; //draw AP and PE Marker
- if(AP>0){
- ctx.beginPath();
- ctx.moveTo(x+(radius+AP)*SC-10*Scale, y);
- ctx.lineTo(x+(radius+AP)*SC+10*Scale, y);
- ctx.closePath();
- ctx.stroke();
- ctx.fillText("AP", x+(radius+AP)*SC+30*Scale, y+6*Scale);
- }
- if(PE>0){
- ctx.beginPath();
- ctx.moveTo(x-(radius+PE)*SC-10*Scale, y);
- ctx.lineTo(x-(radius+PE)*SC+10*Scale, y);
- ctx.stroke();
- ctx.closePath();
- ctx.fillText("PE", x-(radius+PE)*SC-30*Scale, y+6*Scale);
- }
- ctx.strokeStyle = lblue;
- if(Ecc<1){ //draw elliptic orbit
- a = (AP+PE+2*radius)/2;
- ctx.lineWidth = 2/SC;
- ctx.save();
- ctx.translate(Ecc*a*SC+x, y);
- ctx.scale(SC, Math.sqrt(1-Ecc*Ecc)*SC);
- ctx.beginPath();
- ctx.arc(0, 0, a, 0, 2 * Math.PI, false);
- ctx.closePath();
- ctx.stroke()
- ctx.restore();
- }else if(Ecc == 1){ //draw parabolic orbit
- ctx.lineWidth=2;
- for(i=-11;i<=10;i++){
- ctx.beginPath();
- ctx.moveTo(x-(f/2)*SC+(1/(4*f))*(i/m)*(i/m),y+(i/m));
- ctx.lineTo(x-(f/2)*SC+(1/(4*f))*((i+1)/m)*((i+1)/m),y+((i+1)/m));
- ctx.stroke();
- }
- ctx.fillStyle = bg;
- ctx.fillRect(x-184*Scale+3*BWidth+2*BDiffs, y-220*Scale, 200*Scale, 440*Scale);
- }else{ //draw hyperbolic orbit
- var xh = 0;
- var yh = 0;
- a = ((radius+PE)/(Ecc-1));
- b = Math.sqrt(Ecc*a*Ecc*a-a*a);
- ctx.lineWidth=2;
- for(i=0;i<=29;i++){
- ctx.beginPath();
- yh = (i*7*Scale);
- xh = -a*Math.sqrt(1-((yh)*(yh)/(b*b)))*SC;
- ctx.moveTo(x+2*a*SC+xh-Ecc*a*SC,y-yh);
- yh = ((i+1)*7*Scale);
- xh = -a*Math.sqrt(1-((yh)*(yh)/(b*b)))*SC;
- ctx.lineTo(x+2*a*SC+xh-Ecc*a*SC,y-yh);
- ctx.stroke();
- }
- for(i=0;i<=30;i++){
- ctx.beginPath();
- yh = -(i*7*Scale);
- xh = -a*Math.sqrt(1-((yh)*(yh)/(b*b)))*SC;
- ctx.moveTo(x+2*a*SC+xh-Ecc*a*SC,y-yh);
- yh = -((i+1)*7*Scale);
- xh = -a*Math.sqrt(1-((yh)*(yh)/(b*b)))*SC;
- ctx.lineTo(x+2*a*SC+xh-Ecc*a*SC,y-yh);
- ctx.stroke();
- }
- ctx.fillStyle = bg;
- ctx.fillRect(x-184*Scale+3*BWidth+2*BDiffs, y-220*Scale, 200*Scale, 440*Scale);
- }
- ctx.strokeStyle = blue;
- ctx.lineWidth = 4*Scale; //draw body
- ctx.fillStyle = bg;
- ctx.beginPath();
- ctx.arc(x, y, radius*SC, 0, 2 * Math.PI, false);
- ctx.closePath();
- ctx.fill();
- ctx.stroke();
- ctx.fillStyle = blue;
- ctx.font = 24*Scale+'pt Courier New';
- ctx.textAlign = 'center';
- ctx.lineWidth = 2*Scale;
- }
- function draw_sliders(){ //shows percentage of resource and throttle
- var count = 1;
- var BDiffxl = 50*Scale;
- var TDiff = 32*Scale;
- var SldX_R = 1850*Scale;
- var SldX_L = 50*Scale;
- var SldY = 1018*Scale;
- var SWidth = 0;
- var SHeight = 50*Scale;
- if(charge_max > 0){ //calculate total number of siders to draw
- count += 1;
- }
- if(mono_max > 0){
- count += 1;
- }
- if(ox_s_max > 0){
- count += 1;
- }
- if(lf_s_max > 0){
- count += 1;
- }
- if(sf_s_max > 0){
- count += 1;
- }
- SWidth = ((368-55)*Scale/(count-1))-10*Scale+(10*Scale)/(count-1); //calculate width of each slider, minmimum 60
- if(SWidth >60*Scale){
- SWidth = 60*Scale;
- }
- deltx = SWidth;
- if(charge_max > 0){
- drawBar(SldX_R-deltx, SldY, SWidth, SHeight, "CHRG", charge, charge_max);
- deltx+=SWidth+10*Scale;
- }
- if(mono_max > 0){
- drawBar(SldX_R-deltx, SldY, SWidth, SHeight, "MONO", mono, mono_max);
- deltx+=SWidth+10*Scale;
- }
- if(ox_s_max > 0){
- drawBar(SldX_R-deltx, SldY, SWidth, SHeight, "OX", ox_s, ox_s_max);
- deltx+=SWidth+10*Scale;
- }
- if(lf_s_max > 0){
- drawBar(SldX_R-deltx, SldY, SWidth, SHeight, "LF", lf_s, lf_s_max);
- deltx+=SWidth+10*Scale;
- }
- if(sf_s_max > 0){
- drawBar(SldX_R-deltx, SldY, SWidth, SHeight, "SF", sf_s, sf_s_max);
- deltx+=SWidth+10*Scale;
- }
- if(count>1){
- deltx+=27*Scale;
- }else{
- deltx=SWidth;
- }
- drawBar(SldX_R-deltx, SldY, SWidth, SHeight, "TRHL", thrust, 1);
- deltx+=SWidth;
- if(deltx>SWidth){
- drawScale(SldX_R-deltx, SldY, SWidth, SHeight)
- }
- //drawSlider(SldX_R-(deltx+80), SldY, SWidth, SHeight, "THR", thrust, 1);
- function drawScale(x, y, w, h){ //draw percentage scale
- var print = "";
- ctx.font = 18*Scale+'pt Courier New';
- ctx.textAlign = 'right';
- ctx.fillStyle = blue;
- for(i=0;i<=10;i++){ //draw scale
- ctx.fillStyle = lblue;
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = blue.slice(0,-3)+",0.2)";
- ctx.beginPath();
- ctx.moveTo(x+SWidth-30*Scale, y-5*Scale-i*34.5*Scale);
- ctx.lineTo(x+SWidth-15*Scale, y-5*Scale-i*34.5*Scale);
- ctx.stroke();
- }
- ctx.strokeStyle = blue.slice(0,-3)+",0.2)";
- ctx.beginPath();
- ctx.moveTo(x+SWidth-15*Scale, y-350*Scale);
- ctx.lineTo(x+SWidth-15*Scale, y-5*Scale);
- ctx.stroke();
- for(i=0;i<=5;i++){ //draw even percentage big, eg. 0,20,40,60,80,100
- ctx.fillStyle = blue;
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = blue;
- print = 2*i*10;
- ctx.fillText(print.toFixed(0), x+SWidth-45*Scale, y+6*Scale-2*i*34.5*Scale);
- ctx.strokeText(print.toFixed(0), x+SWidth-45*Scale, y+6*Scale-2*i*34.5*Scale);
- }
- for(i=0;i<=4;i++){ //draw odd percentage small, eg. 10, 30, 50, 70, 90
- ctx.font = 14*Scale+'pt Courier New';
- ctx.fillStyle = blue.slice(0,-3)+",0.2)";
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = blue.slice(0,-3)+",0.2)";
- print = (2*i+1)*10;
- ctx.fillText(print.toFixed(0), x+SWidth-45*Scale, y+4*Scale-(2*i+1)*34.5*Scale);
- ctx.strokeText(print.toFixed(0), x+SWidth-45*Scale, y+4*Scale-(2*i+1)*34.5*Scale);
- }
- } //end draw_slider
- function drawBar(x, y, w, h, nme, cur, max){ //draw resource bar
- dy = 0;
- var print = "";
- var grd=ctx.createLinearGradient(0,y-5*Scale+30*Scale,0,y-350*Scale);
- grd.addColorStop(0,lblue);
- grd.addColorStop(1,blue);
- ctx.fillStyle=grd;
- ctx.font = 14*Scale+'pt Courier New';
- ctx.textAlign = 'right';
- ctx.fillStyle = blue;
- for(i=1;i<=10;i++){ //draw bar
- ctx.lineWidth = 2*Scale;
- if(cur/max<(i-1)/10){ //empty rectangles
- ctx.strokeStyle = blue.slice(0,-3)+",0.2)";
- ctx.strokeRect(x, y-i*5*Scale-i*30*Scale, w, 30*Scale);
- }else if(cur/max<i/10){ //partly filled rectangle
- ctx.strokeStyle = blue.slice(0,-3)+",0.2)";
- ctx.strokeRect(x, y-i*5*Scale-i*30*Scale, w, 30*Scale);
- ctx.fillStyle = grd;
- dy = ((cur-((max/10)*(i-1)))/(max/10))*30*Scale;
- ctx.fillRect(x,y-i*5*Scale-30*Scale*i+(30*Scale-dy),w,dy);
- }else{ //filled rectangle
- ctx.fillStyle = grd;
- ctx.fillRect(x, y-i*5*Scale-i*30*Scale, w, 30*Scale);
- }
- }
- if(cur > 0.01 && cur/max < 0.2){ //draw bottom indicator, color based on level
- ctx.fillStyle = lred;
- }else if(cur<0.01){
- ctx.fillStyle = red;
- }else{
- ctx.fillStyle = blue;
- }
- ctx.fillRect(x,y,w,h);
- ctx.font = 14*Scale+'pt Courier New';
- ctx.textAlign = 'left';
- ctx.fillStyle = bg;
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = bg;
- ctx.fillText(nme, x+8*Scale, y+32*Scale);
- ctx.strokeText(nme, x+8*Scale, y+32*Scale);
- } //end draw_bar
- } //end draw_sliders
- function draw_dial_r_p_10(x, y, r, m, n){ //round dial, only positiv values up to 10
- var rad = 68*Scale;
- var w = 0;
- var scale = new Array(0, 0.02, 0.04, 0.06, 0.08, 0.1, 0.2, 0.4, 0.6, 0.8, 1,2,4,6,8,10);
- y +=rad+10*Scale;
- ctx.textAlign = 'center';
- ctx.font = 10*Scale+'pt Courier New';
- ctx.strokeStyle = lblue;
- for(i=0;i<=15;i++){ //drawing scale for sub values, eg. 0.2, 0.4, 0.6...
- ctx.lineWidth = 2*Scale;
- w = Math.sqrt(scale[i])*270/Math.sqrt(scale[15])-45;
- ctx.beginPath();
- ctx.moveTo(x-rad*Math.cos(w*Math.PI/180), y-rad*Math.sin(w*Math.PI/180));
- ctx.lineTo(x-(rad-8*Scale)*Math.cos(w*Math.PI/180), y-(rad-8*Scale)*Math.sin(w*Math.PI/180));
- ctx.stroke();
- }
- for(i=0;i<=3;i++){ //drawing scale for main values, eg 0, 0.1, 1, 10
- ctx.lineWidth = 2*Scale;
- w = Math.sqrt(scale[5*i])*270/Math.sqrt(scale[15])-45;
- ctx.beginPath();
- ctx.moveTo(x-rad*Math.cos(w*Math.PI/180), y-rad*Math.sin(w*Math.PI/180));
- ctx.lineTo(x-(rad-15*Scale)*Math.cos(w*Math.PI/180), y-(rad-15*Scale)*Math.sin(w*Math.PI/180));
- ctx.stroke();
- ctx.lineWidth = 1*Scale;
- ctx.fillText(scale[5*i], x-(rad-30*Scale)*Math.cos(w*Math.PI/180), y+4-(rad-30*Scale)*Math.sin(w*Math.PI/180));
- ctx.strokeText(scale[5*i], x-(rad-30*Scale)*Math.cos(w*Math.PI/180), y+4-(rad-30*Scale)*Math.sin(w*Math.PI/180));
- }
- ctx.strokeStyle = red;
- ctx.lineWidth = 4*Scale;
- if(r>10){ //needle at maximum value
- w = 225;
- ctx.beginPath();
- ctx.beginPath();
- ctx.moveTo(x-(rad-17*Scale)*Math.cos(w*Math.PI/180), y-(rad-17*Scale)*Math.sin(w*Math.PI/180));
- ctx.lineTo(x, y);
- ctx.stroke();
- }else{ //needle for other values
- w = Math.sqrt(r)*270/Math.sqrt(scale[15])-45;
- ctx.beginPath();
- ctx.moveTo(x-(rad-17*Scale)*Math.cos(w*Math.PI/180), y-(rad-17*Scale)*Math.sin(w*Math.PI/180));
- ctx.lineTo(x, y);
- ctx.stroke();
- }
- ctx.lineWidth = 2*Scale; //center circle, middle arc, outer circle and name
- ctx.strokeStyle = lblue;
- ctx.beginPath();
- ctx.arc(x, y, rad, 0.75*Math.PI, 0.25*Math.PI, false);
- ctx.stroke();
- ctx.strokeStyle = blue;
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.arc(x, y, rad+10*Scale, 0, 2*Math.PI, false);
- ctx.closePath();
- ctx.stroke();
- ctx.beginPath();
- ctx.arc(x, y, 5*Scale, 0, 2*Math.PI, false);
- ctx.closePath();
- ctx.fill();
- ctx.strokeStyle = lblue;
- ctx.lineWidth = 1*Scale;
- ctx.textAlign = 'center';
- ctx.font = 14*Scale+'pt Courier New';
- ctx.fillText(n, x, y+rad-10*Scale);
- ctx.strokeText(n, x, y+rad-10*Scale);
- ctx.stroke();
- if(m <= 0){ //dim dial when resource not in vessel
- ctx.fillStyle = bg.slice(0,-3)+",0.8)";
- ctx.fillRect(x-(rad+12*Scale), y-(rad+12*Scale), 2*(rad+12*Scale), 2*(rad+12*Scale));
- }
- }
- function draw_dial_r_p_100(x, y, r, m, n){ //round dial, only positiv values up to 100
- var rad = 68*Scale;
- var w = 0;
- var scale = new Array(0, 0.2, 0.4, 0.6, 0.8, 1, 2, 4, 6, 8, 10,20,40,60,80,100);
- y +=rad+10*Scale;
- ctx.textAlign = 'center';
- ctx.font = 10*Scale+'pt Courier New';
- ctx.strokeStyle = lblue;
- for(i=0;i<=15;i++){ //drawing scale for sub values, eg. 0.2, 0.4, 0.6...
- ctx.lineWidth = 2*Scale;
- w = Math.sqrt(scale[i])*270/Math.sqrt(scale[15])-45;
- ctx.beginPath();
- ctx.moveTo(x-rad*Math.cos(w*Math.PI/180), y-rad*Math.sin(w*Math.PI/180));
- ctx.lineTo(x-(rad-8*Scale)*Math.cos(w*Math.PI/180), y-(rad-8*Scale)*Math.sin(w*Math.PI/180));
- ctx.stroke();
- }
- for(i=0;i<=3;i++){ //drawing scale for main values, eg 0, 0.1, 1, 10
- ctx.lineWidth = 2*Scale;
- w = Math.sqrt(scale[5*i])*270/Math.sqrt(scale[15])-45;
- ctx.beginPath();
- ctx.moveTo(x-rad*Math.cos(w*Math.PI/180), y-rad*Math.sin(w*Math.PI/180));
- ctx.lineTo(x-(rad-15*Scale)*Math.cos(w*Math.PI/180), y-(rad-15*Scale)*Math.sin(w*Math.PI/180));
- ctx.stroke();
- ctx.lineWidth = 1*Scale;
- ctx.fillText(scale[5*i], x-(rad-30*Scale)*Math.cos(w*Math.PI/180), y+4-(rad-30*Scale)*Math.sin(w*Math.PI/180));
- ctx.strokeText(scale[5*i], x-(rad-30*Scale)*Math.cos(w*Math.PI/180), y+4-(rad-30*Scale)*Math.sin(w*Math.PI/180));
- }
- ctx.strokeStyle = red;
- ctx.lineWidth = 4*Scale;
- if(r>100){ //needle at maximum value
- w = 225;
- ctx.beginPath();
- ctx.beginPath();
- ctx.moveTo(x-(rad-17*Scale)*Math.cos(w*Math.PI/180), y-(rad-17*Scale)*Math.sin(w*Math.PI/180));
- ctx.lineTo(x, y);
- ctx.stroke();
- }else{ //needle for other values
- w = Math.sqrt(r)*270/Math.sqrt(scale[15])-45;
- ctx.beginPath();
- ctx.moveTo(x-(rad-17*Scale)*Math.cos(w*Math.PI/180), y-(rad-17*Scale)*Math.sin(w*Math.PI/180));
- ctx.lineTo(x, y);
- ctx.stroke();
- }
- ctx.lineWidth = 2*Scale; //center circle, middle arc, outer circle and name
- ctx.strokeStyle = lblue;
- ctx.beginPath();
- ctx.arc(x, y, rad, 0.75*Math.PI, 0.25*Math.PI, false);
- ctx.stroke();
- ctx.strokeStyle = blue;
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.arc(x, y, rad+10*Scale, 0, 2*Math.PI, false);
- ctx.closePath();
- ctx.stroke();
- ctx.beginPath();
- ctx.arc(x, y, 5*Scale, 0, 2*Math.PI, false);
- ctx.closePath();
- ctx.fill();
- ctx.strokeStyle = lblue;
- ctx.lineWidth = 1*Scale;
- ctx.textAlign = 'center';
- ctx.font = 14*Scale+'pt Courier New';
- ctx.fillText(n, x, y+rad-10*Scale);
- ctx.strokeText(n, x, y+rad-10*Scale);
- ctx.stroke();
- if(m <= 0){ //dim dial when resource not in vessel
- ctx.fillStyle = bg.slice(0,-3)+",0.8)";
- ctx.fillRect(x-(rad+12*Scale), y-(rad+12*Scale), 2*(rad+12*Scale), 2*(rad+12*Scale));
- }
- }
- function draw_dial_r_pm(x, y, r, n){ //round dial, positiv and negativ values
- var rad = 70*Scale;
- var w = 0;
- var scale = new Array(0, 0.02, 0.04, 0.06, 0.08, 0.1, 0.2, 0.4, 0.6, 0.8, 1);
- y +=rad+10*Scale;
- ctx.textAlign = 'center';
- ctx.font = 10*Scale+'pt Courier New';
- ctx.strokeStyle = lblue;
- for(i=-10;i<=0;i++){ //draw scale for negativ sub values, eg. -0.6, -0.4, -0.2...
- ctx.lineWidth = 2*Scale;
- w = -Math.sqrt(scale[-i])*135/Math.sqrt(scale[10])+90;
- ctx.beginPath();
- ctx.moveTo(x-rad*Math.cos(w*Math.PI/180), y-rad*Math.sin(w*Math.PI/180));
- ctx.lineTo(x-(rad-8*Scale)*Math.cos(w*Math.PI/180), y-(rad-8*Scale)*Math.sin(w*Math.PI/180));
- ctx.stroke();
- }
- for(i=-2;i<=0;i++){ //draw scale for negativ main values, eg. -1, -0.1
- ctx.lineWidth = 2*Scale;
- w = -Math.sqrt(scale[-5*i])*135/Math.sqrt(scale[10])+90;
- ctx.beginPath();
- ctx.moveTo(x-rad*Math.cos(w*Math.PI/180), y-rad*Math.sin(w*Math.PI/180));
- ctx.lineTo(x-(rad-15*Scale)*Math.cos(w*Math.PI/180), y-(rad-15*Scale)*Math.sin(w*Math.PI/180));
- ctx.stroke();
- ctx.lineWidth = 1*Scale;
- ctx.fillText(-scale[-5*i], x-(rad-30*Scale)*Math.cos(w*Math.PI/180), y+4-(rad-30*Scale)*Math.sin(w*Math.PI/180));
- ctx.strokeText(-scale[-5*i], x-(rad-30*Scale)*Math.cos(w*Math.PI/180), y+4-(rad-30*Scale)*Math.sin(w*Math.PI/180));
- }
- for(i=1;i<=10;i++){ //draw scale for positiv sub values, eg. 0.2, 0.4, 0.6...
- ctx.lineWidth = 2*Scale;
- w = Math.sqrt(scale[i])*135/Math.sqrt(scale[10])+90;
- ctx.beginPath();
- ctx.moveTo(x-rad*Math.cos(w*Math.PI/180), y-rad*Math.sin(w*Math.PI/180));
- ctx.lineTo(x-(rad-8*Scale)*Math.cos(w*Math.PI/180), y-(rad-8*Scale)*Math.sin(w*Math.PI/180));
- ctx.stroke();
- }
- for(i=1;i<=2;i++){ //draw scale for negativ main values, eg. 0.1, 1
- ctx.lineWidth = 2*Scale;
- w = Math.sqrt(scale[5*i])*135/Math.sqrt(scale[10])+90;
- ctx.beginPath();
- ctx.moveTo(x-rad*Math.cos(w*Math.PI/180), y-rad*Math.sin(w*Math.PI/180));
- ctx.lineTo(x-(rad-15*Scale)*Math.cos(w*Math.PI/180), y-(rad-15*Scale)*Math.sin(w*Math.PI/180));
- ctx.stroke();
- ctx.lineWidth = 1*Scale;
- ctx.fillText(scale[5*i], x-(rad-30*Scale)*Math.cos(w*Math.PI/180), y+4-(rad-30*Scale)*Math.sin(w*Math.PI/180));
- ctx.strokeText(scale[5*i], x-(rad-30*Scale)*Math.cos(w*Math.PI/180), y+4-(rad-30*Scale)*Math.sin(w*Math.PI/180));
- }
- ctx.strokeStyle = red;
- ctx.lineWidth = 4*Scale;
- if(r>1){ //needle at maximum value
- w = 225;
- ctx.beginPath();
- ctx.beginPath();
- ctx.moveTo(x-(rad-17*Scale)*Math.cos(w*Math.PI/180), y-(rad-17*Scale)*Math.sin(w*Math.PI/180));
- ctx.lineTo(x, y);
- ctx.stroke();
- }else if(r<-1){ //needle at minimum value
- w = -45;
- ctx.beginPath();
- ctx.beginPath();
- ctx.moveTo(x-(rad-17*Scale)*Math.cos(w*Math.PI/180), y-(rad-17*Scale)*Math.sin(w*Math.PI/180));
- ctx.lineTo(x, y);
- ctx.stroke();
- }else if(r>=0){ //needle for positiv values
- w = Math.sqrt(r)*135/Math.sqrt(scale[10])+90;
- ctx.beginPath();
- ctx.moveTo(x-(rad-17*Scale)*Math.cos(w*Math.PI/180), y-(rad-17*Scale)*Math.sin(w*Math.PI/180));
- ctx.lineTo(x, y);
- ctx.stroke();
- }else{ //needle for negativ values
- w = -Math.sqrt(-r)*135/Math.sqrt(scale[10])+90;
- ctx.beginPath();
- ctx.moveTo(x-(rad-17*Scale)*Math.cos(w*Math.PI/180), y-(rad-17*Scale)*Math.sin(w*Math.PI/180));
- ctx.lineTo(x, y);
- ctx.stroke();
- }
- ctx.lineWidth = 2*Scale; //center circle, middle arc, outer circle and name
- ctx.strokeStyle = lblue;
- ctx.beginPath();
- ctx.arc(x, y, rad, 0.75*Math.PI, 0.25*Math.PI, false);
- ctx.stroke();
- ctx.strokeStyle = blue;
- ctx.fillStyle = blue;
- ctx.beginPath();
- ctx.arc(x, y, rad+10*Scale, 0, 2*Math.PI, false);
- ctx.closePath();
- ctx.stroke();
- ctx.beginPath();
- ctx.arc(x, y, 5*Scale, 0, 2*Math.PI, false);
- ctx.closePath();
- ctx.fill();
- ctx.strokeStyle = lblue;
- ctx.lineWidth = 1*Scale;
- ctx.textAlign = 'center';
- ctx.font = 14*Scale+'pt Courier New';
- ctx.fillText(n, x, y+rad-10*Scale);
- ctx.strokeText(n, x, y+rad-10*Scale);
- ctx.stroke();
- }
- if(Math.abs(gee)>=3 && Math.abs(gee)<5){ //draw gee indicator
- Button(100*Scale, 1018*Scale, BWidth, BHeight,"Warn", gee.toFixed(2), "G");
- }else if(Math.abs(gee)<3){
- Button(100*Scale, 1018*Scale, BWidth, BHeight,"IndOn", gee.toFixed(2), "G");
- }else{
- Button(100*Scale, 1018*Scale, BWidth, BHeight,"AlarmOn", gee.toFixed(2), "G");
- }
- if(con=="false" && set==false){ //draw "connecting, please wait" overlay
- draw_connect();
- }
- if(set==true){ //draw settings
- draw_settings();
- }
- function draw_settings(){ //settings menu)
- SBackground();
- Button(SX+SWidth-30*Scale, SY+10*Scale, 20*Scale, 20*Scale,"CLOSE", "", "R");
- STitle("IP and Port", SX+32*Scale, SY+32*Scale);
- Button(SX+32*Scale, SY+56*Scale, 400*Scale, 64*Scale,"IP", IP, "C");
- STitle("Refresh Rate (ms)", SX+480*Scale, SY+32*Scale);
- Button(SX+480*Scale, SY+56*Scale, 288*Scale, 64*Scale,"RATE", rate, "C");
- Button(SX+32*Scale, SY+176*Scale, 248*Scale, 64*Scale,"C1", "Color 1", "C");
- Button(SX+312*Scale, SY+176*Scale, 64*Scale, 64*Scale,"C1R", "", "R");
- Button(SX+32*Scale, SY+272*Scale, 248*Scale, 64*Scale,"H1", "Highlight 1", "C");
- Button(SX+312*Scale, SY+272*Scale, 64*Scale, 64*Scale,"H1R", "", "R");
- Button(SX+32*Scale, SY+368*Scale, 248*Scale, 64*Scale,"BG", "Background", "C");
- Button(SX+312*Scale, SY+368*Scale, 64*Scale, 64*Scale,"BGR", "", "R");
- STitle("Colors", SX+32*Scale, SY+152*Scale);
- Button(SX+424*Scale, SY+176*Scale, 248*Scale, 64*Scale,"C2", "Color 2", "C");
- Button(SX+704*Scale, SY+176*Scale, 64*Scale, 64*Scale,"C2R", "", "R");
- Button(SX+424*Scale, SY+272*Scale, 248*Scale, 64*Scale,"H2", "Highlight 2", "C");
- Button(SX+704*Scale, SY+272*Scale, 64*Scale, 64*Scale,"H2R", "", "R");
- Button(SX+424*Scale, SY+368*Scale, 248*Scale, 64*Scale,"MK", "Marker", "C");
- Button(SX+704*Scale, SY+368*Scale, 64*Scale, 64*Scale,"MKR", "", "R");
- function STitle(t, x, y){
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = red;
- ctx.fillStyle = red;
- ctx.font = 16*Scale+'pt Courier New';
- ctx.textAlign = 'left';
- ctx.fillText(t, x, y+8*Scale);
- ctx.strokeText(t, x, y+8*Scale);
- }
- function SBackground(){
- ctx.clearRect(SX, SY, SWidth, SHeight);
- ctx.fillStyle = "rgba(0,0,0,0.75)";
- ctx.fillRect(0, 0, WWidth, WHeight);
- ctx.fillStyle = setbg;
- ctx.fillRect(SX, SY, SWidth, SHeight);
- }
- }
- function draw_connect(){ //connecting overlay
- ctx.fillStyle = "rgba(0,0,0,0.75)";
- ctx.fillRect(0, 0, WWidth, WHeight);
- ctx.fillStyle = setbg;
- ctx.fillRect(960*Scale-200*Scale, WHeight/2-100*Scale, 400*Scale, 200*Scale);
- ctx.lineWidth = 2*Scale;
- ctx.strokeStyle = red;
- ctx.fillStyle = red;
- ctx.font = 32*Scale+'pt Courier New';
- ctx.textAlign = 'center';
- ctx.fillText("CONNECTING", 960*Scale, WHeight/2-20*Scale);
- ctx.strokeText("CONNECTING", 960*Scale, WHeight/2-20*Scale);
- ctx.lineWidth = 1*Scale;
- ctx.strokeStyle = lred;
- ctx.fillStyle = lred;
- ctx.font = 24*Scale+'pt Courier New';
- ctx.textAlign = 'center';
- ctx.fillText("PLEASE WAIT", 960*Scale, WHeight/2+40*Scale);
- ctx.strokeText("PLEASE WAIT", 960*Scale, WHeight/2+40*Scale);
- }
- } //end draw_buttons
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement