SHARE
TWEET

Untitled

a guest Jul 17th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let sun, planet;
  2. function setup() {
  3.   createCanvas(400, 400);
  4.   sun = new Sun();
  5.   planet = new Planet();
  6.  
  7.  
  8. }
  9.  
  10. class Sun {
  11.   constructor() {
  12.   this.x = height/2;
  13.   this.y = width/2;
  14. }  
  15.   move() {
  16.   this.x = this.x;
  17.   this.y = this.y;
  18. }
  19.  
  20.   show(){
  21. stroke(3);
  22. fill(255, 255, 0);
  23. circle(this.x, this.y, 50);
  24.    
  25.   }
  26. }
  27.  
  28. class Planet {
  29.   constructor() {
  30.   this.x = height/1.25;
  31.   this.y = width/2;
  32. }  
  33.  
  34.   move() {
  35.   //this.x = this.x;
  36.   //this.y = this.y;
  37.   angle += 1 * frameCount(0.01);
  38.   x = Sun.x + cos(angle) * 1;
  39.   y = Sun.y + sin(angle) * 1;
  40.  
  41. }
  42.  
  43.   show(){
  44. stroke(3);
  45. fill(0, 130, 255);
  46. circle(this.x, this.y, 25);
  47.    
  48.   }
  49. }
  50.  
  51. function draw() {
  52.   background(225);
  53.   sun.show();
  54.   sun.move();
  55.   planet.show();
  56.   planet.move();
  57.  
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top