Fixed up the graphs a whole lot!

This commit is contained in:
Shoofle 2013-09-04 13:54:38 -04:00
parent f3b535afb2
commit a2fab9b420
2 changed files with 56 additions and 26 deletions

View File

@ -8,13 +8,13 @@
<div class="row-fluid">
<div id="fuel-management-1" class="span4 offset4">
<script type="text/javascript">
function heyo(q) {
if (q.temperature.value < q.ignition_threshhold.value) {
return -0.5*q.temperature.value;
function heyo(sq) {
if (sq.temperature.value < sq.ignition_threshhold.value) {
return -0.5*sq.temperature.value;
}
return q.temperature.value*q.fuel_flow_rate.value - 0.5*q.temperature.value;
return sq.temperature.value*sq.fuel_flow_rate.value - 0.5*sq.temperature.value;
}
engine($('#fuel-management-1'), heyo);
var e1=engine($('#fuel-management-1'), heyo);
</script>
<div class="flow_rate">
<label for="fuel">Fuel Flow Rate</label>
@ -24,25 +24,26 @@
<span><span class="temp-out">0</span> degrees</span>
<span class="noignition label label-info">No ignition</span>
<span class="damage label label-warning">DAMAGE!</span>
<div class="potential_plot" style="width:100%;height:400px"></div>
<div class="potential_plot" style="width:100%;height:300px"></div>
</div>
<span class="sidenote span4">The dotted lines indicate what the curve will look like if you adjust the fuel flow rate up or down a little bit.</span>
</div>
<p>It's interesting! Or maybe it's not. I threw this together trying to think of what an interesting way for an engine to work might be. The fundamental relationship here is:</p>
\[\frac{\partial T}{\partial t} = c_F T F - c_T (T - T_0)\]
<p>That is, at any given moment, the temperature is changing (\(\frac{\partial T}{\partial t}\)) by increasing proportional to the temperature times the fuel flow rate (\(c_F T F\)) and decreasing proportional to the difference between the chamber temperature and the ambient temperature (\(c_T (T - T_0)\)). The deignition isn't described in this formula, but it's pretty simple - the \(c_F T F\) factor becomes zero when the temperature is less than <span data-var="ignition_threshhold">2</span> degrees.</p>
<p>As it turns out, (surprise of surprises!) that description in a formula is pretty useless for actually understanding how this feels. The key was to look at it as a function of the temperature. See, the player changes \(F\), and I want to get a feel for how the temperature's going to change. So I made a graph with respect to \(T\) where the slope is given by \(\frac{\partial T}{\partial t}\). <span class="sidenote">Note that this is not just going to undo the partial derivative. In this graph, we're integrating against \(T\), not \(t\). Roughly, this graph should be thought of as one where the temperature would slide down hills. Anyway.</span></p>
<p>As it turns out, (surprise of surprises!) that description in a formula is pretty useless for actually understanding how this feels. The key was to look at it as a function of the temperature. See, the player changes \(F\), and I want to get a feel for how the temperature's going to change. So I made a graph with respect to \(T\) where the slope is given by \(\frac{\partial T}{\partial t}\). <span class="sidenote span4">Note that this is not just going to undo the partial derivative. In this graph, we're integrating against \(T\), not \(t\). Roughly, this graph should be thought of as one where the temperature would slide down hills. Anyway.</span></p>
<p>You can feel free to slide around the fuel flow rate slider to play with this. When the graph is flat, that temperature is stable. (Remember: temperature is on the x-axis.)</p>
<p>Well. This is <em>terrible</em>. There aren't any stable points!
<div class="row-fluid">
<div id="fuel-management-2" class="span4 offset4">
<script type="text/javascript">
function heyo2(q) {
if (q.temperature.value < q.ignition_threshhold.value) {
function heyo2(sq) {
if (sq.temperature.value < sq.ignition_threshhold.value) {
return -0.5;
}
return q.temperature.value*q.fuel_flow_rate.value - 0.5;
return sq.temperature.value*sq.fuel_flow_rate.value - 0.5;
}
engine($('#fuel-management-2'), heyo2);
var e2=engine($('#fuel-management-2'), heyo2);
</script>
<div class="flow_rate">
<label for="fuel">Fuel Flow Rate</label>
@ -52,7 +53,7 @@
<span><span class="temp-out">0</span> degrees</span>
<span class="noignition label label-info">No ignition</span>
<span class="damage label label-warning">DAMAGE!</span>
<div class="potential_plot" style="width:100%;height:400px"></div>
<div class="potential_plot" style="width:100%;height:300px"></div>
</div>
</div>
</article>

View File

@ -1,3 +1,4 @@
var a=true;
function engine(element, reaction_rate_function) {
var container = $(element);
var graph, graph_plot;
@ -18,7 +19,7 @@ function engine(element, reaction_rate_function) {
};
q.fuel_flow_rate = {
"update": function () { this.value = container.find('[name=fuel]').val(); },
"update": function () { this.value = parseFloat(container.find('[name=fuel]').val()); },
"out": function () { update_graph(); },
"value": 0,
};
@ -28,31 +29,59 @@ function engine(element, reaction_rate_function) {
"out": function() {},
"value": 2,
};
var ignition_boost = 5;
q.ignition_boost = {
"update": function () {},
"out": function() {},
"value": 5,
}
var damage_threshhold = 10;
var temperature_decay = 0.5;
var timestep=10;
var graph_config = { xaxis: { min:0, max:15 }, yaxis: { min:-4, max:4 } };
var graph_config = {
xaxis: { min:0, max:15, tickSize: 3 },
yaxis: { min:-4, max:4, show: false },
series: {
lines: {
lineWidth: 4,
},
points: {
show: true,
radius: 0.1,
}
},
colors: ['red'],
};
function update_graph() {
var step_size = 0.2;
var step_size = 0.3;
var data = [], area=0;
for (var i=0; i<15; i+=step_size) {
area -= step_size * reaction_rate_function({
"fuel_flow_rate": q.fuel_flow_rate,
"temperature": { "value":i },
"ignition_threshhold": q.ignition_threshhold,
});
data.push([i, area]);
var data = [
{data: [], lines: {show: false}, points: {show: true}},
{data: [], lines: {show: true}, points: {show: false}},
{data: [], lines: {show: false}, points: {show: true}},
];
var points = [$.extend({}, q), jQuery.extend({}, q), jQuery.extend({}, q)];
var flow_value = q.fuel_flow_rate.value;
for (var series=0; series<3; series++) {
points[series].fuel_flow_rate = {"value": flow_value + 0.01*(series-1)};
points[series].temperature = {"value": 0};
var prev=0;
for (var i=0; i<15; i+=step_size) {
points[series].temperature.value = i;
prev = prev - step_size * reaction_rate_function(points[series]);
data[series].data.push([i, prev]);
}
}
graph_plot.setData([data]);
if (a) { console.log(points); a=false; }
graph_plot.setData(data);
graph_plot.draw();
}
var a, b;
container.ready(function () {
container.find('[name=ignition]').on('click', function() { q.temperature.value += ignition_boost; });
container.find('[name=ignition]').on('click', function() { q.temperature.value += q.ignition_boost.value; });
a = setInterval(jQuery.each, timestep, q, function(name, x) { x.update(); });
b = setInterval(jQuery.each, timestep, q, function(name, x) { x.out(); });
graph = container.find('.potential_plot');