orbitdemo.pde 762 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. int x;
  2. int y;
  3. int r = 200;
  4. void setup()
  5. {
  6. size(640, 480);
  7. background(0,0,0);
  8. x = 0;
  9. y = 0;
  10. }
  11. void draw()
  12. {
  13. float t = millis() / 1000.0f;
  14. x = (int) (350 + (r * cos(t) * 1.3));
  15. y = (int) (240 + r * sin(t));
  16. background(0,0,0);
  17. //orbit
  18. stroke(0, 0, 255, 128);
  19. fill(0,0,0,0);
  20. ellipse(240, 1240, 2000, 2000);
  21. //planet
  22. stroke(0,255,0, 255);
  23. fill(0,255,0, 0);
  24. ellipse(250, 240, 150, 150);
  25. stroke(255,0,0, 255);
  26. fill(255,0,0,255);
  27. rect(250 - 5, 240 - 4, 10, 8);
  28. //orbit
  29. stroke(0, 0, 255, 128);
  30. fill(0,0,0,0);
  31. ellipse(350, 240, 520, 400);
  32. //moon
  33. stroke(128,128,128,255);
  34. fill(128,128,128,0);
  35. ellipse(x, y, 48, 48);
  36. stroke(255,255,0,255);
  37. fill(255,255,0,255);
  38. rect(x - 5, y - 4, 10, 8);
  39. }