Advertisement
Guest User

Planet Class

a guest
Aug 14th, 2017
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. // Example 14-18: Object-oriented solar system
  2.  
  3. class Planet {
  4. // Each planet object keeps track of its own angle of rotation.
  5. float theta; // Rotation around sun
  6. float diameter; // Size of planet
  7. float distance; // Distance from sun
  8. float orbitspeed; // Orbit speed
  9. float resetingDistance ;
  10. color planetColor;
  11. boolean colorChange = false;
  12.  
  13.  
  14. Planet(float distance_, float diameter_) {
  15. distance = distance_;
  16. resetingDistance = distance_ ;
  17. diameter = diameter_;
  18. theta = 0;
  19. orbitspeed = random(0.01, 0.03);
  20. //planetColor = color( random(255), random(255), random(255), random(255));
  21. }
  22.  
  23. void update() {
  24. // Increment the angle to rotate
  25. theta += orbitspeed;
  26. }
  27.  
  28. void display() {
  29. // Before rotation and translation, the state of the matrix is saved with pushMatrix().
  30. pushMatrix();
  31. // Rotate orbit
  32. rotate(theta);
  33. // Translate out distance
  34. translate(distance, 0);
  35. stroke(0);
  36. fill(175);
  37.  
  38. if (colorChange == true) {
  39. //fill(random(255), random(255), random(255), random(255));
  40. planetColor = color( random(255), random(255), random(255), random(255));
  41. }
  42.  
  43. ellipse(0, 0, diameter, diameter);
  44. // Once the planet is drawn, the matrix is restored with popMatrix() so that the next planet is not affected.
  45. popMatrix();
  46.  
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement