Skip to content

Commit ff0b0e5

Browse files
committed
add Inheritance example
1 parent fe481b3 commit ff0b0e5

File tree

3 files changed

+66
-63
lines changed

3 files changed

+66
-63
lines changed

src/data/examples/en/11_Objects/04_Inheritance.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
* another is called a subclass, and the object it inherits from is called
66
* a superclass. A subclass extends the superclass.
77
*/
8-
98
let spots, arm;
9+
1010
function setup() {
1111
createCanvas(640, 360);
1212
arm = new SpinArm(width/2, height/2, 0.01);
1313
spots = new SpinSpots(width/2, height/2, -0.02, 90.0);
1414
}
15+
1516
function draw() {
1617
background(204);
1718
arm.update();
@@ -33,38 +34,38 @@ class SpinArm {
3334
}
3435

3536
display() {
36-
strokeWeight(1);
37-
stroke(0);
38-
push();
39-
translate(this.x, this.y);
40-
this.angle += this.speed;
41-
rotate(this.angle);
42-
line(0, 0, 165, 0);
43-
pop();
37+
strokeWeight(1);
38+
stroke(0);
39+
push();
40+
translate(this.x, this.y);
41+
this.angle += this.speed;
42+
rotate(this.angle);
43+
line(0, 0, 165, 0);
44+
pop();
4445
}
4546
}
4647

4748
class SpinSpots {
4849
constructor(x, y, s, d) {
49-
this.x = x;
50-
this.y = y;
51-
this.speed = s;
50+
this.x = x;
51+
this.y = y;
52+
this.speed = s;
5253
this.dim = d;
53-
this.angle = 0.0;
54+
this.angle = 0.0;
5455
}
5556

5657
update() {
5758
this.angle += this.speed;
5859
}
5960

6061
display() {
61-
noStroke();
62-
push();
63-
translate(this.x, this.y);
64-
this.angle += this.speed;
65-
rotate(this.angle);
66-
ellipse(-this.dim/2, 0, this.dim, this.dim);
67-
ellipse(this.dim/2, 0, this.dim, this.dim);
68-
pop();
62+
noStroke();
63+
push();
64+
translate(this.x, this.y);
65+
this.angle += this.speed;
66+
rotate(this.angle);
67+
ellipse(-this.dim/2, 0, this.dim, this.dim);
68+
ellipse(this.dim/2, 0, this.dim, this.dim);
69+
pop();
6970
}
7071
}

src/data/examples/es/11_Objects/04_Inheritance.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
* another is called a subclass, and the object it inherits from is called
66
* a superclass. A subclass extends the superclass.
77
*/
8-
98
let spots, arm;
9+
1010
function setup() {
1111
createCanvas(640, 360);
1212
arm = new SpinArm(width/2, height/2, 0.01);
1313
spots = new SpinSpots(width/2, height/2, -0.02, 90.0);
1414
}
15+
1516
function draw() {
1617
background(204);
1718
arm.update();
@@ -33,38 +34,38 @@ class SpinArm {
3334
}
3435

3536
display() {
36-
strokeWeight(1);
37-
stroke(0);
38-
push();
39-
translate(this.x, this.y);
40-
this.angle += this.speed;
41-
rotate(this.angle);
42-
line(0, 0, 165, 0);
43-
pop();
37+
strokeWeight(1);
38+
stroke(0);
39+
push();
40+
translate(this.x, this.y);
41+
this.angle += this.speed;
42+
rotate(this.angle);
43+
line(0, 0, 165, 0);
44+
pop();
4445
}
4546
}
4647

4748
class SpinSpots {
4849
constructor(x, y, s, d) {
49-
this.x = x;
50-
this.y = y;
51-
this.speed = s;
50+
this.x = x;
51+
this.y = y;
52+
this.speed = s;
5253
this.dim = d;
53-
this.angle = 0.0;
54+
this.angle = 0.0;
5455
}
5556

5657
update() {
5758
this.angle += this.speed;
5859
}
5960

6061
display() {
61-
noStroke();
62-
push();
63-
translate(this.x, this.y);
64-
this.angle += this.speed;
65-
rotate(this.angle);
66-
ellipse(-this.dim/2, 0, this.dim, this.dim);
67-
ellipse(this.dim/2, 0, this.dim, this.dim);
68-
pop();
62+
noStroke();
63+
push();
64+
translate(this.x, this.y);
65+
this.angle += this.speed;
66+
rotate(this.angle);
67+
ellipse(-this.dim/2, 0, this.dim, this.dim);
68+
ellipse(this.dim/2, 0, this.dim, this.dim);
69+
pop();
6970
}
7071
}

src/data/examples/zh-Hans/11_Objects/04_Inheritance.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
* another is called a subclass, and the object it inherits from is called
66
* a superclass. A subclass extends the superclass.
77
*/
8-
98
let spots, arm;
9+
1010
function setup() {
1111
createCanvas(640, 360);
1212
arm = new SpinArm(width/2, height/2, 0.01);
1313
spots = new SpinSpots(width/2, height/2, -0.02, 90.0);
1414
}
15+
1516
function draw() {
1617
background(204);
1718
arm.update();
@@ -33,38 +34,38 @@ class SpinArm {
3334
}
3435

3536
display() {
36-
strokeWeight(1);
37-
stroke(0);
38-
push();
39-
translate(this.x, this.y);
40-
this.angle += this.speed;
41-
rotate(this.angle);
42-
line(0, 0, 165, 0);
43-
pop();
37+
strokeWeight(1);
38+
stroke(0);
39+
push();
40+
translate(this.x, this.y);
41+
this.angle += this.speed;
42+
rotate(this.angle);
43+
line(0, 0, 165, 0);
44+
pop();
4445
}
4546
}
4647

4748
class SpinSpots {
4849
constructor(x, y, s, d) {
49-
this.x = x;
50-
this.y = y;
51-
this.speed = s;
50+
this.x = x;
51+
this.y = y;
52+
this.speed = s;
5253
this.dim = d;
53-
this.angle = 0.0;
54+
this.angle = 0.0;
5455
}
5556

5657
update() {
5758
this.angle += this.speed;
5859
}
5960

6061
display() {
61-
noStroke();
62-
push();
63-
translate(this.x, this.y);
64-
this.angle += this.speed;
65-
rotate(this.angle);
66-
ellipse(-this.dim/2, 0, this.dim, this.dim);
67-
ellipse(this.dim/2, 0, this.dim, this.dim);
68-
pop();
62+
noStroke();
63+
push();
64+
translate(this.x, this.y);
65+
this.angle += this.speed;
66+
rotate(this.angle);
67+
ellipse(-this.dim/2, 0, this.dim, this.dim);
68+
ellipse(this.dim/2, 0, this.dim, this.dim);
69+
pop();
6970
}
7071
}

0 commit comments

Comments
 (0)