Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let sun, planet;
- function setup() {
- createCanvas(400, 400);
- sun = new Sun();
- planet = new Planet();
- }
- class Sun {
- constructor() {
- this.x = height/2;
- this.y = width/2;
- }
- move() {
- this.x = this.x;
- this.y = this.y;
- }
- show(){
- stroke(3);
- fill(255, 255, 0);
- circle(this.x, this.y, 50);
- }
- }
- class Planet {
- constructor() {
- this.x = height/1.25;
- this.y = width/2;
- }
- move() {
- //this.x = this.x;
- //this.y = this.y;
- angle += 1 * frameCount(0.01);
- x = Sun.x + cos(angle) * 1;
- y = Sun.y + sin(angle) * 1;
- }
- show(){
- stroke(3);
- fill(0, 130, 255);
- circle(this.x, this.y, 25);
- }
- }
- function draw() {
- background(225);
- sun.show();
- sun.move();
- planet.show();
- planet.move();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement