From fcfa8c028afdef5d2f9283fadc67977b9b0dcca5 Mon Sep 17 00:00:00 2001 From: Alejandro Cremades Date: Thu, 6 Jan 2022 12:22:56 +0900 Subject: [PATCH] Started a sketch about class inheritance --- inheritance/inheritance.js | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 inheritance/inheritance.js diff --git a/inheritance/inheritance.js b/inheritance/inheritance.js new file mode 100644 index 0000000..c346aa8 --- /dev/null +++ b/inheritance/inheritance.js @@ -0,0 +1,55 @@ +var pochi, arinko, takosuke; +function setup() { + createCanvas(400, 400); + pochi = new Inu(100, 100); + arinko = new Ari(100, 200); + takosuke = new Tako(100, 300); +} + +function draw() { + background(127); + pochi.display(); + arinko.display(); + takosuke.display(); +} +class Ikimono { + constructor(ashi, x, y) { + this.ashi = ashi; + this.x = x; + this.y = y; + this.namae = 'ikimono'; + } + display() { + text(this.ashi, this.x, this.y); + } +} + +class Inu extends Ikimono { + constructor(x, y) { + super(4, x, y); + this.namae = 'inu'; + } + display() { + text(this.namae + ": " + this.ashi, this.x, this.y); + } +} + +class Ari extends Ikimono { + constructor(x, y) { + super(6, x, y); + this.namae = 'ari'; + } + display() { + text(this.namae + ": " + this.ashi, this.x, this.y); + } +} + +class Tako extends Ikimono { + constructor(x, y) { + super(8, x, y); + this.namae = 'tako'; + } + display() { + text(this.namae + ": " + this.ashi, this.x, this.y); + } +}