Skip to content

Conversation

@ShenpaiSharma
Copy link
Contributor

Fixes #921

Changes:
Changes Inheritance code such that both the classes SpinArms and SpinSpots extend the Spin class. As initially in Inheritance, two separate classes are defined, which are defining their own spin classes and not using extends keyword.

Changed code:

let spots, arm;

function setup() {
  createCanvas(640, 360);
  arm = new SpinArm(width/2, height/2, 0.01);
  spots = new SpinSpots(width/2, height/2, -0.02, 90.0);
}

function draw() {
  background(204);
  arm.update();
  arm.display();
  spots.update();
  spots.display();
}

class Spin {
  constructor(x,y,s) {
    this.x = x;
    this.y = y;
    this.speed = s;
    this.angle = 0.0;
  }
  
  update() {
    this.angle += this.speed;
  }
}

class SpinArm extends Spin {
  constructor(x, y, s) {
    super(x,y,s)
  }

  display() {
    strokeWeight(1);
    stroke(0);
    push();
    translate(this.x, this.y);
    this.angle += this.speed;
    rotate(this.angle);
    line(0, 0, 165, 0);
    pop();
  }
}

class SpinSpots extends Spin {
  constructor(x, y, s, d) {
    super(x,y,s)
    this.dim = d;
  }

  display() {
    noStroke();
    push();
    translate(this.x, this.y);
    this.angle += this.speed;
    rotate(this.angle);
    ellipse(-this.dim/2, 0, this.dim, this.dim);
    ellipse(this.dim/2, 0, this.dim, this.dim);
    pop();
  }
}

Screenshots of the change:

Intially:
image

After change:
image

@ShenpaiSharma
Copy link
Contributor Author

Hi, @limzykenneth , can you please review my PR?

Copy link
Member

@limzykenneth limzykenneth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some formatting changes required. Once those are fixed we can merge. Thanks!

this.angle = 0.0;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an extra white space here. It would help if you set your text editor to automatically trim trailing whitespaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will take care of that. Thanks!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The white space is not yet removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, sorry, I thought of something different.

@limzykenneth limzykenneth merged commit f0b56e6 into processing:main Feb 3, 2021
@limzykenneth
Copy link
Member

Looks good. Thanks!

@ShenpaiSharma ShenpaiSharma deleted the Fixes-Issue_#921 branch February 3, 2021 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inheritance example does not actually implement inheritance using the extends keyword

2 participants