Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <head>
- <link rel="stylesheet" type="text/css" href="http://calander.site90.net/Traffic.css">
- <script type="text/javascript" src="http://calander.site90.net/createline.js" ></script>
- <script type="text/javascript">
- //define global variables
- var Lroads = 0; //count the number of roads for the line genorator
- //define nodes
- var nodes = new Array(); var nox = new Array(); var noy = new Array();
- //define roads
- var Aroad = new Array(); //start
- var Broad = new Array(); //finish
- var Croad = new Array(); //resistance
- //End of definition of global variables
- function main(){
- //initiate nodes
- nodes[0] = 5; nox[0] = 100; noy[0] = 100;
- nodes[1] = 2; nox[1] = 100; noy[1] = 200;
- for (i=2;i<7;i++){
- nodes[i] = 10; nox[i] = 100 * i; noy[i] = 200;
- }
- nodes[7] = 1000; nox[7] = 600; noy[7] = 100;
- drawnodes();
- //initiate roads
- //road 1
- Aroad[0] = 0; //node 1
- Broad[0] = 1; //node 2
- Croad[0] = 2; //inverse o flow
- init(0);
- for (i=1;i<7;i++){
- //road i
- Aroad[i] = i; //node 1
- Broad[i] = i+1; //node 2
- Croad[i] = 1; //inverse to flow
- init(i);
- }
- }//end of main
- function init(road)
- {
- Lroads++;
- glue = '<div id="' + Lroads + '"></div>';
- writting(glue);
- var demoElement = document.getElementById(Lroads);
- demoElement.appendChild(createLine(nox[Aroad[road]], noy[Aroad[road]], nox[Broad[road]], noy[Broad[road]]));
- }
- //a place that HTML can be written to without wiping what has come before
- function writting(text){
- document.getElementById('edspace').innerHTML = document.getElementById('edspace').innerHTML + text;
- }
- function drawnodes(){
- for (i=0;i<nodes.length;i++){
- glue="";
- glue = glue + ('<div style="Position:absolute;left:' + nox[i] + 'px;top:' + noy[i] + 'px;" id="node:' + i + '">' + nodes[i] + '</div>');
- writting(glue);
- }
- }
- function run(){
- nodes[7] = nodes[7] * 2;
- var flow = 0;
- for (var i=0;i<Aroad.length;i++){
- flow = Math.round((nodes[Aroad[i]] - nodes[Broad[i]])/Croad[i]);
- nodes[Aroad[i]] = nodes[Aroad[i]] - flow;
- nodes[Broad[i]] = nodes[Broad[i]] + flow;
- }
- nodes[0] = Math.round(nodes[0]/4);
- editnodes();
- setTimeout('run();', 1000);
- }
- function editnodes(){
- for (i=0;i<nodes.length;i++){
- document.getElementById('node:' + i).innerHTML = nodes[i];
- }
- }
- </script>
- </head>
- <body onload="main();">
- <h1>Flowing</h1>
- <p>V=IR dQ/dt = I so V=R.dQ/dt</p><p> <a href=βhttp://www.vwi.tu-dresden.de/~treiber/MicroApplet/IDM.htmlβ>Speed</a> <a href=βhttp://www.vwi.tu-dresden.de/~treiber/MicroApplet/MOBIL.htmlβ> Lane changing</a></p>
- <input type="button" value="run" onclick="run();" />
- <x id="edspace"></x>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment