Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. float theta;
  2. float dTheta;
  3. Sun theSun;
  4. float fps;
  5.  
  6. void setup() {
  7. size(480, 480);
  8. noStroke();
  9. colorMode(HSB, 360, 100, 100);
  10. theta = 0;
  11. dTheta = 0;
  12. theSun = new Sun(50, width / 2, height / 2);
  13. }
  14.  
  15. void draw() {
  16. background(0, 0, 100);
  17. theSun.drawFigure();
  18. theSun.move();
  19. }
  20.  
  21. class Sun {
  22. float d; // 直径(50)
  23. float x; // 中心のx座標(240)
  24. float y; // 中心のy座標(240)
  25. Earth theEarth;
  26. Sun(float d, float x, float y) {
  27. this.d = d;
  28. this.x = x;
  29. this.y = y;
  30. theEarth = new Earth(0.6 * d, 150); // 直径および回転の半径を与える
  31. }
  32. void move() {
  33. theEarth.move(x, y); // 地球を動かす (太陽の周りを回るので太陽の位置を与える)
  34. }
  35. void drawFigure() {
  36. theEarth.drawFigure(); // Earthオブジェクトに描画を指示
  37. fill(30, 100, 100);
  38. ellipse(x, y, d, d); // 自分自身を描画
  39. }
  40. }
  41.  
  42. class Earth {
  43. float d;
  44. float x;
  45. float y;
  46. float x1;
  47. float y1;
  48. float radEarth;
  49. float orbitRadius = 100;
  50. Moon theMoon;
  51. Earth(float d, float x) {
  52. this.d = d;
  53. this.x = x;
  54. theMoon = new Moon (0.3 * d, 30);
  55. }
  56. void drawFigure() {
  57. fill(216, 86, 84);
  58. ellipse(x + 240, y + 240, d, d);
  59. theMoon.drawFigure();
  60. }
  61. void move(float x, float y) {
  62. theMoon.move(x, y);
  63. theta += 1;
  64. radEarth = radians(theta);
  65. this.x = orbitRadius * cos(radEarth);
  66. this.y = -orbitRadius * sin(radEarth);
  67. }
  68. }
  69.  
  70. class Moon {
  71. float d;
  72. float x;
  73. float y;
  74. float x1;
  75. float y1;
  76. float x2;
  77. float y2;
  78. float radMoon;
  79. float orbitRadius = 30;
  80. Moon(float d, float x) {
  81. this.d = d;
  82. this.x = x;
  83. }
  84. void drawFigure() {
  85. fill(50, 69, 61);
  86. ellipse(x, y, d, d);
  87. }
  88. void move(float x, float y) {
  89. dTheta += 2;
  90. radMoon = radians(dTheta);
  91. this.x = x + orbitRadius * cos(radMoon);
  92. this.y = x - orbitRadius * sin(radMoon);
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement