Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. <div id="game">
  2. <button class="user" data-name="red">Red</button>
  3. <button class="user" data-name="green">Green</button>
  4. <button class="user" data-name="blue">Blue</button>
  5. <button id="test">Change Color</button>
  6.  
  7. id="rendered-js">
  8. (function () {
  9. var Montanha, MontanhaRange, dt, MontanhaRanges, janela;
  10.  
  11. janela = Sketch.create();
  12.  
  13. janela.mouse.x = janela.width / 10;
  14.  
  15. janela.mouse.y = janela.height;
  16.  
  17. MontanhaRanges = [];
  18.  
  19. dt = 1;
  20. p = 90;
  21.  
  22. Montanha = function (config) {
  23. return this.reset(config);
  24. };
  25.  
  26. $(document).ready(function() {
  27. var user = "none";
  28. $(".user").click(function() {
  29. user = $(this).attr("data-name");
  30. });
  31. $("#test").click(function() {
  32. window.location.reload();
  33. p = 240
  34. });
  35. });
  36.  
  37. // Montanhas
  38.  
  39. Montanha.prototype.reset = function (config) {
  40. this.layer = config.layer;
  41. this.x = config.x;
  42. this.y = config.y;
  43. this.width = config.width;
  44. this.height = config.height;
  45. return this.color = config.color;
  46. };
  47.  
  48. // Montanha tamanho
  49.  
  50. MontanhaRange = function (config) {
  51. this.x = 0;
  52. this.Montanhas = [];
  53. this.layer = config.layer;
  54. this.width = {
  55. min: config.width.min,
  56. max: config.width.max };
  57.  
  58. this.height = {
  59. min: config.height.min,
  60. max: config.height.max };
  61.  
  62. this.speed = config.speed;
  63. this.color = config.color;
  64. this.populate();
  65. return this;
  66. };
  67.  
  68. MontanhaRange.prototype.populate = function () {
  69. var newHeight, newWidth, results, totalWidth;
  70. totalWidth = 0;
  71. results = [];
  72. while (totalWidth <= janela.width + this.width.max * 4) {if (window.CP.shouldStopExecution(0)) break;
  73. newWidth = round(random(this.width.min, this.width.max));
  74. newHeight = round(random(this.height.min, this.height.max));
  75. this.Montanhas.push(new Montanha({
  76. layer: this.layer,
  77. x: this.Montanhas.length === 0 ? 0 : this.Montanhas[this.Montanhas.length - 1].x + this.Montanhas[this.Montanhas.length - 1].width,
  78. y: janela.height - newHeight,
  79. width: newWidth,
  80. height: newHeight,
  81. color: this.color }));
  82.  
  83. results.push(totalWidth += newWidth);
  84. }window.CP.exitedLoop(0);
  85. return results;
  86. };
  87.  
  88. MontanhaRange.prototype.update = function () {
  89. var firstMontanha, lastMontanha, newHeight, newWidth;
  90. this.x -= janela.mouse.x * this.speed * dt;
  91. firstMontanha = this.Montanhas[0];
  92. if (firstMontanha.width + firstMontanha.x + this.x < -this.width.max) {
  93. newWidth = round(random(this.width.min, this.width.max));
  94. newHeight = round(random(this.height.min, this.height.max));
  95. lastMontanha = this.Montanhas[this.Montanhas.length - 1];
  96. firstMontanha.reset({
  97. layer: this.layer,
  98. x: lastMontanha.x + lastMontanha.width,
  99. y: janela.height - newHeight,
  100. width: newWidth,
  101. height: newHeight,
  102. color: this.color });
  103.  
  104. return this.Montanhas.push(this.Montanhas.shift());
  105. }
  106. };
  107.  
  108. MontanhaRange.prototype.render = function () {
  109. var c, d, i, j, pointCount, ref;
  110. janela.save();
  111. janela.translate(this.x, (janela.height - janela.mouse.y) / 20 * this.layer);
  112. janela.beginPath();
  113. pointCount = this.Montanhas.length;
  114. janela.moveTo(this.Montanhas[0].x, this.Montanhas[0].y);
  115. for (i = j = 0, ref = pointCount - 2; j <= ref; i = j += 1) {if (window.CP.shouldStopExecution(1)) break;
  116. c = (this.Montanhas[i].x + this.Montanhas[i + 1].x) / 2;
  117. d = (this.Montanhas[i].y + this.Montanhas[i + 1].y) / 2;
  118. janela.quadraticCurveTo(this.Montanhas[i].x, this.Montanhas[i].y, c, d);
  119. }window.CP.exitedLoop(1);
  120. janela.lineTo(janela.width - this.x, janela.height);
  121. janela.lineTo(0 - this.x, janela.height);
  122. janela.closePath();
  123. janela.fillStyle = this.color;
  124. janela.fill();
  125. return janela.restore();
  126. };
  127.  
  128. // SETUP
  129.  
  130. janela.setup = function () {
  131. var i, results;
  132. i = 5;
  133. results = [];
  134. while (i--) {if (window.CP.shouldStopExecution(2)) break;
  135. results.push(MontanhaRanges.push(new MontanhaRange({
  136. layer: i + 1,
  137. width: {
  138. min: (i + 1) * 50,
  139. max: (i + 1) * 70 },
  140.  
  141. height: {
  142. min: 200 - i * 40,
  143. max: 300 - i * 40 },
  144.  
  145. speed: (i + 1) * .003,
  146. color: 'hsl(' + p + ', ' + ((i + 1) * 1 + 10) + '%, ' + (75 - i * 13) + '% )' })));
  147. console.log("Hello world!");
  148.  
  149. }window.CP.exitedLoop(2);
  150. return results;
  151. };
  152.  
  153. // CLEAR
  154.  
  155. janela.clear = function () {
  156. return janela.clearRect(0, 0, janela.width, janela.height);
  157. };
  158.  
  159. // UPDATE
  160.  
  161. janela.update = function () {
  162. var i, results;
  163. dt = janela.dt < .1 ? .1 : janela.dt / 16;
  164. dt = dt > 5 ? 5 : dt;
  165. i = MontanhaRanges.length;
  166. results = [];
  167. while (i--) {if (window.CP.shouldStopExecution(3)) break;
  168. results.push(MontanhaRanges[i].update(i));
  169. }window.CP.exitedLoop(3);
  170. return results;
  171. };
  172.  
  173. // DRAW
  174.  
  175. janela.draw = function () {
  176. var i, results;
  177. i = MontanhaRanges.length;
  178. results = [];
  179. while (i--) {if (window.CP.shouldStopExecution(4)) break;
  180. results.push(MontanhaRanges[i].render(i));
  181. }window.CP.exitedLoop(4);
  182. return results;
  183. };
  184.  
  185. // Mousemove Fix
  186.  
  187. $(window).on('mousemove', function (e) {
  188. janela.mouse.x = e.pageX;
  189. return janela.mouse.y = e.pageY;
  190. });
  191.  
  192. }).call(this);
  193.  
  194. color: 'hsl(' + p + ', ' + ((i + 1) * 1 + 10) + '%, ' + (75 - i * 13) + '% )' })));
  195.  
  196. $(document).ready(function() {
  197. var user = "none";
  198. $(".user").click(function() {
  199. user = $(this).attr("data-name");
  200. });
  201. $("#test").click(function() {
  202. window.location.reload();
  203. p = 240
  204. });
  205. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement