开发者

Dynamically-changing variables random intergers

The numbers themselves aren't relevant. I have a list of variables that are used to track a moving vehicle. UT开发者_如何学PythonC Time:, Latitude:, Longitude:, Speed:, Heading:, Steering:, Odometer:(PPM), GPS Status:, STWS Status:

Like i said the numbers aren't relevant, and neither is the math. I just need to simulate dynamically changing integers for each variable. For instance, Speed:25. then the 25 become a 26, then a 28, then a 15 and so on. I will implement this code, and then set the min and max for each variable. I just need to show customers that the vehicle tracking system monitor can display changing values for each variable.

Thank you.


$("#the_span_id").text(n); and hook it up to a JavaScript timer event.


It sounds like what you need is a jQuery countdown. Take a look at this link:

http://www.tripwiremagazine.com/2011/04/9-cool-jquery-countdown-scripts.html


You could do something along the following lines:

var DynVar = {
    variables: [],
    timer: 0,
    numIntervals: 0,
    counter: 0,

    updateVar: function(v) {
        v.value = Math.random() * (v.max - v.min) + v.min;
    },

    createVar: function(name, min, max) {
        var v = {"name": name, "min": min, "max": max};
        DynVar.updateVar(v);
        DynVar.variables.push(v);
        return v;
    },

    update: function() {
        for (i = 0; i < DynVar.variables.length; ++i) {
            var v = DynVar.variables[i];
            DynVar.updateVar(v);
            console.log(DynVar.counter + ": " + v.name + ": " + v.value);
        }
        if (DynVar.counter++ >= DynVar.numIntervals) {
            clearInterval(DynVar.timer);
        }
    },

    start: function(interval, numIntervals) {
        DynVar.counter = 0;
        DynVar.numIntervals = numIntervals;
        DynVar.timer = setInterval(DynVar.update, interval);
    }
};

DynVar.createVar("speed", 10, 30);
DynVar.createVar("latitude", 20, 22);
DynVar.start(1000, 3);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜