Advertisement
Guest User

Untitled

a guest
May 28th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. var fc = require('fc');
  2. var hsv = require('hsv2rgb');
  3. var TAU = Math.PI*2;
  4.  
  5. var planets = [{
  6. center: [0, 0],
  7. color: 'rgba(255, 0, 0, .2)',
  8. stroke: 'rgba(255, 0, 0, 1)',
  9. radius: 100,
  10. rings: 5
  11. }];
  12.  
  13. var player = window.player = {
  14. center: [0, 0],
  15. planet: 0,
  16. ring: 3,
  17. angle: 0,
  18. velocity: .05
  19. };
  20.  
  21.  
  22. var ctx = fc(function() {
  23. ctx.clear();
  24.  
  25. var w = ctx.canvas.width;
  26. var h = ctx.canvas.height;
  27. var hw = (w/2)|0;
  28. var hh = (h/2)|0;
  29. ctx.translate(hw, hh)
  30.  
  31. ctx.scale(2, 2);
  32. var planet = planets[player.planet];
  33. var x = Math.cos(player.angle) * planet.radius + player.ring * 10;
  34. var y = Math.sin(player.angle) * planet.radius + player.ring * 10;
  35. console.log(x, y)
  36. ctx.translate(x, y);
  37.  
  38. planets.forEach(function(planet) {
  39. ctx.translate(planet.center[0], planet.center[1]);
  40. ctx.beginPath();
  41. ctx.fillStyle = planet.color;
  42. ctx.strokeStyle = planet.stroke;
  43. ctx.arc(0, 0, planet.radius, 0, TAU, false);
  44. ctx.fill();
  45. ctx.stroke();
  46.  
  47. for (var i=0; i<planet.rings; i++) {
  48. ctx.beginPath()
  49. var r = planet.radius + (i + 1) * 10;
  50. ctx.moveTo(r, 0);
  51. ctx.arc(0, 0, r, 0, TAU, false)
  52. ctx.strokeStyle = "grey";
  53. ctx.stroke();
  54. }
  55. });
  56.  
  57. player.angle += player.velocity / player.ring;
  58. ctx.save()
  59. ctx.rotate(player.angle + Math.PI / 2);
  60. ctx.translate(0, planet.radius + player.ring * 10, planet.radius + player.ring * 10);
  61.  
  62. ctx.beginPath()
  63. ctx.arc(0, 0, 5, 0, TAU, false);
  64. ctx.fillStyle = 'orange';
  65. ctx.fill();
  66. ctx.restore();
  67.  
  68.  
  69. }, true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement