помогите разобраться с кодом
помогите разобраться с кодом, есть симулятор графических повреждений называется BeamNG drive, в интерфейсе есть скрипт который считывает время ( разгон до 100, торможение, называется perfomance timers ), как изменить код так чтобы тот считал время прохождения заданного расстояния допустим 1000 условных единиц (Считает он как в имперской системе так и в метрической), что нужно переделать, может нужно какие то переменные добавить?
function SimplePerfTimers(){} SimplePerfTimers.prototype.initialize = function(){ this.table = $('<table><thead><tr> <th> <b>Type</b> </th> <th> <b>Start</b> </th> <th> <b>End</b> </th> <th> <b>Time</b> </th> <th> <b>Distance</b> </th></tr></thead><tbody id="resultstable"><tr></tr></tbody></table>').appendTo(this.rootElement).addClass('table'); this.div = $('<div></div>').appendTo(this.rootElement).addClass('div'); this.wheelTimer = 0; this.wheelTimerState = 0; // 0 - No timer / 1 - Acceleration / 3 - braking this.timerSpeedLimit = null; this.speedMargin = 0.5; this.startPos = null; this.startVelo = null; this.stopVelo = null; this.testing = ""; this.aborted = ""; this.prevTime = 0; this.curTime = 0; //If no unit was previously selected, default to km/h if ((this.persistance.Unit != "Imperial") && (this.persistance.Unit != "Metric")) this.persistance.Unit = "Metric"; var self = this; this.table.click(function(){self.toggleUnit();}); }; SimplePerfTimers.prototype.toggleUnit = function(){ //Toggle between Imperial and Metric, save the option to persistance system this.persistance.Unit = this.persistance.Unit === 'Imperial' ? 'Metric' : 'Imperial'; HookManager.trigger('Message',{msg:'Switched SimplePerfTimers to ' + this.persistance.Unit + " speed",ttl: 2}); this.save(); }; function appendToTable (data) { $('#resultstable tr:first').before('<tr style="text-align:right;"> <td style="text-align:center;"> ' + data[0] + ' </td> <td> ' + data[1] + ' </td> <td> ' + data[2] + ' </td> <td> ' + data[3] + ' </td> <td> ' + data[4] + ' </td> </tr>'); } SimplePerfTimers.prototype.update = function(streams){ var throttle = streams.electrics.throttle.toFixed(2); var brake = streams.electrics.brake.toFixed(2); var position = streams.sensors.position; if (this.persistance.Unit == "Metric"){ var airspeed = (streams.electrics.airspeed*3.6).toFixed(2); var speedUnits = "km/h"; this.timerSpeedLimit = 100; } else { var airspeed = (streams.electrics.airspeed*2.23693629).toFixed(2); var speedUnits = "MPH"; this.timerSpeedLimit = 60; } this.prevTime = this.curTime; this.curTime = performance.now(); var dt = (this.curTime - this.prevTime)/1000; // speed testing if (throttle > 0.5 && airspeed > this.speedMargin && airspeed < this.speedMargin*3 && this.wheelTimerState === 0) { this.wheelTimerState = 1; this.wheelTimer = 0; this.startPos = position; this.startVelo = airspeed; this.aborted = ""; this.testing = ""; } else if (this.wheelTimerState == 1) { this.wheelTimer = this.wheelTimer + dt; if (airspeed > this.timerSpeedLimit) { // console.log("TOP SPEED") var stopPos = position; this.stopVelo = airspeed; var distance = Math.sqrt( Math.pow((stopPos.x - this.startPos.x), 2) + Math.pow((stopPos.y - this.startPos.y), 2) ); this.wheelTimerState = 0; this.testing = ""; appendToTable(["Speed", Math.floor(this.startVelo) + " " + speedUnits, Math.floor(this.stopVelo) + " " + speedUnits, this.wheelTimer.toFixed(2) + " s", distance.toFixed(2) + " m"]); } if (throttle < 0.5) { // console.log("ABORTED"); this.aborted = "Aborted: Throttle < 0.5"; this.wheelTimerState = 0; } } if (this.wheelTimerState == 1) { this.testing = "Speed Testing... " + airspeed + " " + speedUnits + ", " + this.wheelTimer.toFixed(2) + " s"; } //brake testing if (brake > 0.5 && airspeed > 10 - this.speedMargin && this.wheelTimerState === 0) { this.wheelTimerState = 3; this.wheelTimer = 0; this.startPos = position; this.startVelo = airspeed; this.aborted = ""; this.testing = ""; } else if (this.wheelTimerState == 3) { this.wheelTimer = this.wheelTimer + dt; if (airspeed < this.speedMargin) { // console.log("STOPPED") var stopPos = position; this.stopVelo = airspeed; var distance = Math.sqrt( Math.pow((stopPos.x - this.startPos.x), 2) + Math.pow((stopPos.y - this.startPos.y), 2) ).toFixed(2); this.wheelTimerState = 0; this.testing = ""; appendToTable(["Brake", Math.floor(this.startVelo) + " " + speedUnits, Math.floor(this.stopVelo) + " " + speedUnits, this.wheelTimer.toFixed(2) + " s", distance + " m"]); } if (brake < 0.5) { // console.log("ABORTED"); this.aborted = "Aborted: Brake < 0.5"; this.wheelTimerState = 0; } } if (this.wheelTimerState == 3) { this.testing = "Brake Testing... " + airspeed + " " + speedUnits + ", " + this.wheelTimer.toFixed(2) + " s"; } var str = this.testing; str += "<br>" + this.aborted; this.div.html(str); }; P.S. пруф на скачивание, директория самого файла BeamNG.drive\html\apps\SimplePerfTimers Заранее благодарю за помощь |
Помогите, пожалуйста. Программа не считает стоимость заливки, пишет NAN... Срочно нужно, 2 дня маюсь(((( делала первый раз калькулятор))))
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Калькулятор на JavaScript</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> <script type="text/javascript"> /* * Функция подсчета стоимости заливки наливного пола */ function calc() { //получаем ссылку на элемент Select (Тип пола) var type_floor = document.getElementById("type_floor"); //получаем ссылку на элемент Select (Дополнительные работы) var additional_works = document.getElementById("additional_works"); //получаем ссылку на чекбокс (Требуется стяжка?) var is_html = document.getElementById("is_html"); //получаем ссылку на элемент input (Площадь) var count = document.getElementById("area"); //получаем ссылку на элемент span, в него будем писать стоимость заливки var result = document.getElementById("result"); var price = ((document.getElementById("type_floor").value*docu ment.getElementById("area").value) + (document.getElementById("additional_works").value *document.getElementById("area").value) + (document.getElementById("is_html")*document.getEl ementById("area").value)); 0; result.innerHTML = price; } </script> </head> <body> <b>Тип пола:</b><br/> <select onchange="calc()" id="type_floor"> <option value="0">Выбрать</option> <option value="4800">Декоративный пол</option> <option value="4500">Декоративные полы с узором</option> <option value="2800">Одноцветный наливной пол</option> </select><br/> Дополнительные работы:</b><br/> <select onchange="calc()" id="additional_works"> <option value="0">Выбрать</option> <option value="200">Демонтаж плитки</option> <option value="150">Демонтаж деревянного пола</option> <option value="100">Демонтаж ламината</option> <option value="50">Демонтаж паркета</option> <option value="50">Демонтаж линолеума</option> </select><br/> <input type="checkbox" onchange="calc()" value="250" id="is_html" /> <label for="is_html">Требуется стяжка?</label> Площадь: <input type="text" id="area" onchange="calc()" /> <div>Стоимость заливки пола: <span id="result">0</span> руб.</div> </body> </html> |
Не верно выбрал категорию, тебе в JS.
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Калькулятор на JavaScript</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> <script type="text/javascript"> /* * Функция подсчета стоимости заливки наливного пола */ function calc() { var type_floor = document.getElementById("type_floor").value; var additional_works = document.getElementById("additional_works").value; var is_html = document.getElementById("is_html").value; var count = document.getElementById("area").value; var result = document.getElementById("result"); var price = ((type_floor * count) + (additional_works * count) + (is_html * count)); result.innerHTML = price; } </script> </head> <body> <b>Тип пола:</b><br/> <select onchange="calc()" id="type_floor"> <option value="0">Выбрать</option> <option value="4800">Декоративный пол</option> <option value="4500">Декоративные полы с узором</option> <option value="2800">Одноцветный наливной пол</option> </select><br/> Дополнительные работы:</b><br/> <select onchange="calc()" id="additional_works"> <option value="0">Выбрать</option> <option value="200">Демонтаж плитки</option> <option value="150">Демонтаж деревянного пола</option> <option value="100">Демонтаж ламината</option> <option value="50">Демонтаж паркета</option> <option value="50">Демонтаж линолеума</option> </select><br/> <input type="checkbox" onchange="calc()" value="250" id="is_html" /> <label for="is_html">Требуется стяжка?</label> Площадь: <input type="text" id="area" onchange="calc()" /> <div>Стоимость заливки пола: <span id="result">0</span> руб.</div> </body> </html> |
Часовой пояс GMT +3, время: 17:08. |