big steppy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

165 line
3.1 KiB

  1. var baseHeight = 3.65;
  2. var baseMass = 1360;
  3. var scale = 1;
  4. var victims =
  5. {
  6. "Person": 0,
  7. "Car": 0,
  8. "Bus": 0,
  9. "Motorcycle": 0,
  10. "House": 0,
  11. "Train": 0,
  12. "Parking Garage": 0,
  13. "Overpass": 0
  14. }
  15. function getOnePrey(area)
  16. {
  17. var potential = ["Person", "Car", "Bus", "House", "Train", "Parking Garage"];
  18. var potAreas = []
  19. potential.forEach(function (x) {
  20. potAreas.push([x,areas[x]]);
  21. });
  22. potAreas = potAreas.sort(function (x,y) {
  23. return x[1] < y[1];
  24. });
  25. for (var i=0; i<potAreas.length; i++) {
  26. x = potAreas[i];
  27. if (x[1] < area) {
  28. return new things[x[0]](1);
  29. }
  30. };
  31. return new Person(1);
  32. }
  33. function getPrey(region, area)
  34. {
  35. switch(region)
  36. {
  37. case "suburb": return suburbPrey(area);
  38. }
  39. }
  40. function suburbPrey(area)
  41. {
  42. return fill_area(area, {"Person": 0.5, "House": 0.5, "Car": 0.2});
  43. }
  44. function updateVictims(prey)
  45. {
  46. var sums = prey.sum();
  47. for (var key in sums) {
  48. if (sums.hasOwnProperty(key)) {
  49. victims[key] += sums[key];
  50. }
  51. }
  52. }
  53. function scaleAddMass(scale, baseMass, mass)
  54. {
  55. var startMass = Math.pow(scale, 3) * baseMass;
  56. var newMass = startMass + mass;
  57. return Math.pow(newMass / baseMass, 1/3) ;
  58. }
  59. function feed()
  60. {
  61. var log = document.getElementById("log");
  62. var line = document.createElement('div');
  63. var prey = getPrey("suburb", 0.5*scale*scale);
  64. updateVictims(prey);
  65. line.innerHTML = prey.eat();
  66. log.appendChild(line);
  67. var preyMass = prey.sum_property("mass");
  68. scale = scaleAddMass(scale, baseMass, preyMass);
  69. update();
  70. }
  71. function stomp()
  72. {
  73. var log = document.getElementById("log");
  74. var line = document.createElement('div');
  75. var prey = getPrey("suburb", 1.5*scale*scale);
  76. updateVictims(prey);
  77. line.innerHTML = prey.stomp();
  78. log.appendChild(line);
  79. var preyMass = prey.sum_property("mass");
  80. scale = scaleAddMass(scale, baseMass, preyMass);
  81. update();
  82. }
  83. function anal_vore()
  84. {
  85. var log = document.getElementById("log");
  86. var line = document.createElement('div');
  87. var prey = getOnePrey(scale*scale*2)
  88. updateVictims(prey);
  89. line.innerHTML = prey.anal_vore();
  90. log.appendChild(line);
  91. var preyMass = prey.sum_property("mass");
  92. scale = scaleAddMass(scale, baseMass, preyMass);
  93. update();
  94. }
  95. function update()
  96. {
  97. var log = document.getElementById("log");
  98. log.scrollTop = log.scrollHeight;
  99. var height = baseHeight * scale;
  100. var mass = baseMass * Math.pow(scale, 3);
  101. document.getElementById("height").innerHTML = "Height: " + Math.round(height * 3) + " feet";
  102. document.getElementById("mass").innerHTML = "Mass: " + Math.round(mass * 2.2) + " pounds";
  103. for (var key in victims){
  104. if (victims.hasOwnProperty(key)) {
  105. if (victims[key] > 0)
  106. document.getElementById(key).innerHTML = key + ": " + victims[key];
  107. }
  108. }
  109. }
  110. function pick_move()
  111. {
  112. var choice = Math.random();
  113. if (choice < 0.2) {
  114. anal_vore();
  115. setTimeout(pick_move, 4000);
  116. } else if (choice < 0.6) {
  117. stomp();
  118. setTimeout(pick_move, 1500);
  119. } else {
  120. feed();
  121. setTimeout(pick_move, 2000);
  122. }
  123. }
  124. window.addEventListener('load', function(event) {
  125. setTimeout(pick_move, 2000);
  126. update();
  127. });