Skip to content

Commit 686b5ae

Browse files
committed
add composite object example
1 parent a7de77b commit 686b5ae

File tree

3 files changed

+79
-70
lines changed

3 files changed

+79
-70
lines changed

src/data/examples/en/11_Objects/05_Composite_Objects.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@ function draw() {
1717
er2.transmit();
1818
}
1919

20-
Egg = function(xpos, ypos, t, s) {
21-
this.x = xpos;
22-
this.y = ypos;
23-
this.tilt = t;
24-
this.scalar = s / 100.0;
25-
this.angle = 0.0;
20+
class Egg {
21+
constructor(xpos, ypos, t, s) {
22+
this.x = xpos;
23+
this.y = ypos;
24+
this.tilt = t;
25+
this.scalar = s / 100.0;
26+
this.angle = 0.0;
27+
}
2628

27-
this.wobble = function() {
29+
wobble() {
2830
this.tilt = cos(this.angle) / 8;
2931
this.angle += 0.1;
3032
}
3133

32-
this.display = function() {
34+
display() {
3335
noStroke();
3436
fill(255);
3537
push();
@@ -74,21 +76,22 @@ class Ring {
7476
}
7577
}
7678

77-
EggRing = function(x, y, t, sp) {
78-
let ovoid;
79-
let circle = new Ring();
80-
this.x = x;
81-
this.y = y;
82-
this.t = t;
83-
this.sp = sp;
84-
ovoid = new Egg(this.x, this.y, this.t, this.sp);
85-
circle.start(this.x, this.y - this.sp/2);
79+
class EggRing {
80+
constructor(x, y, t, sp) {
81+
this.x = x;
82+
this.y = y;
83+
this.t = t;
84+
this.sp = sp;
85+
this.circle = new Ring();
86+
this.ovoid = new Egg(this.x, this.y, this.t, this.sp);
87+
this.circle.start(this.x, this.y - this.sp/2);
88+
}
8689

87-
this.transmit = function() {
88-
ovoid.wobble();
89-
ovoid.display();
90-
circle.grow();
91-
circle.display();
90+
transmit() {
91+
this.ovoid.wobble();
92+
this.ovoid.display();
93+
this.circle.grow();
94+
this.circle.display();
9295
if (circle.on == false) {
9396
circle.on = true;
9497
}

src/data/examples/es/11_Objects/05_Composite_Objects.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@ function draw() {
1717
er2.transmit();
1818
}
1919

20-
Egg = function(xpos, ypos, t, s) {
21-
this.x = xpos;
22-
this.y = ypos;
23-
this.tilt = t;
24-
this.scalar = s / 100.0;
25-
this.angle = 0.0;
20+
class Egg {
21+
constructor(xpos, ypos, t, s) {
22+
this.x = xpos;
23+
this.y = ypos;
24+
this.tilt = t;
25+
this.scalar = s / 100.0;
26+
this.angle = 0.0;
27+
}
2628

27-
this.wobble = function() {
29+
wobble() {
2830
this.tilt = cos(this.angle) / 8;
2931
this.angle += 0.1;
3032
}
3133

32-
this.display = function() {
34+
display() {
3335
noStroke();
3436
fill(255);
3537
push();
@@ -74,23 +76,24 @@ class Ring {
7476
}
7577
}
7678

77-
EggRing = function(x, y, t, sp) {
78-
let ovoid;
79-
let circle = new Ring();
80-
this.x = x;
81-
this.y = y;
82-
this.t = t;
83-
this.sp = sp;
84-
ovoid = new Egg(this.x, this.y, this.t, this.sp);
85-
circle.start(this.x, this.y - this.sp/2);
79+
class EggRing {
80+
constructor(x, y, t, sp) {
81+
this.x = x;
82+
this.y = y;
83+
this.t = t;
84+
this.sp = sp;
85+
this.circle = new Ring();
86+
this.ovoid = new Egg(this.x, this.y, this.t, this.sp);
87+
this.circle.start(this.x, this.y - this.sp/2);
88+
}
8689

87-
this.transmit = function() {
88-
ovoid.wobble();
89-
ovoid.display();
90-
circle.grow();
91-
circle.display();
92-
if (circle.on == false) {
93-
circle.on = true;
90+
transmit() {
91+
this.ovoid.wobble();
92+
this.ovoid.display();
93+
this.circle.grow();
94+
this.circle.display();
95+
if (this.circle.on == false) {
96+
this.circle.on = true;
9497
}
9598
}
9699
}

src/data/examples/zh-Hans/11_Objects/05_Composite_Objects.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@ function draw() {
1717
er2.transmit();
1818
}
1919

20-
Egg = function(xpos, ypos, t, s) {
21-
this.x = xpos;
22-
this.y = ypos;
23-
this.tilt = t;
24-
this.scalar = s / 100.0;
25-
this.angle = 0.0;
20+
class Egg {
21+
constructor(xpos, ypos, t, s) {
22+
this.x = xpos;
23+
this.y = ypos;
24+
this.tilt = t;
25+
this.scalar = s / 100.0;
26+
this.angle = 0.0;
27+
}
2628

27-
this.wobble = function() {
29+
wobble() {
2830
this.tilt = cos(this.angle) / 8;
2931
this.angle += 0.1;
3032
}
3133

32-
this.display = function() {
34+
display() {
3335
noStroke();
3436
fill(255);
3537
push();
@@ -74,23 +76,24 @@ class Ring {
7476
}
7577
}
7678

77-
EggRing = function(x, y, t, sp) {
78-
let ovoid;
79-
let circle = new Ring();
80-
this.x = x;
81-
this.y = y;
82-
this.t = t;
83-
this.sp = sp;
84-
ovoid = new Egg(this.x, this.y, this.t, this.sp);
85-
circle.start(this.x, this.y - this.sp/2);
79+
class EggRing {
80+
constructor(x, y, t, sp) {
81+
this.x = x;
82+
this.y = y;
83+
this.t = t;
84+
this.sp = sp;
85+
this.circle = new Ring();
86+
this.ovoid = new Egg(this.x, this.y, this.t, this.sp);
87+
this.circle.start(this.x, this.y - this.sp/2);
88+
}
8689

87-
this.transmit = function() {
88-
ovoid.wobble();
89-
ovoid.display();
90-
circle.grow();
91-
circle.display();
92-
if (circle.on == false) {
93-
circle.on = true;
90+
transmit() {
91+
this.ovoid.wobble();
92+
this.ovoid.display();
93+
this.circle.grow();
94+
this.circle.display();
95+
if (this.circle.on == false) {
96+
this.circle.on = true;
9497
}
9598
}
9699
}

0 commit comments

Comments
 (0)