Created
February 7, 2020 08:40
-
-
Save tkojitu/d765ce035441c56280960c209c19768b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class { | |
constructor() { | |
this.services = []; | |
this.instances = []; | |
} | |
define(name, fn) { | |
this.services[name] = fn; | |
} | |
geti(name) { | |
if (this.instances[name]) { | |
return this.instances[name]; | |
} | |
var fn = this.services[name]; | |
this.instances[name] = fn(this); | |
return this.instances[name]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<script type="module" src="./scripts/main.js"></script> | |
</head> | |
<body> | |
<div id="openspace"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Container from "./Container.js"; | |
import Sticker from "./Sticker.js"; | |
window.addEventListener( | |
"load", | |
function() { | |
let c = new Container(); | |
c.define( | |
"openspace", | |
function(c) { | |
return document.getElementById("openspace"); | |
}); | |
c.define( | |
"sticker", | |
function(c) { | |
return new Sticker(); | |
}); | |
c.geti("sticker").init(c.geti("openspace")); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class { | |
constructor() { | |
this.canvas = null; | |
} | |
init(parent) { | |
this.canvas = this.newCanvas(); | |
parent.appendChild(this.canvas); | |
this.draw(); | |
} | |
newCanvas() { | |
let canvas = document.createElement("canvas"); | |
canvas.width = 512; | |
canvas.height = 512; | |
canvas.id = "canvas"; | |
canvas.style = "border:1px solid"; | |
return canvas; | |
} | |
draw() { | |
let gx = this.canvas.getContext("2d"); | |
this.drawRuby(gx); | |
this.drawStrawberry(gx); | |
this.drawSample(gx); | |
} | |
drawRuby(gx) { | |
gx.beginPath(); | |
gx.moveTo(0, 200); | |
gx.lineTo(200, 500); | |
gx.lineTo(400, 200); | |
gx.lineTo(300, 100); | |
gx.lineTo(100, 100); | |
gx.lineTo(0, 200); | |
gx.fillStyle = "red"; | |
gx.fill(); | |
} | |
drawStrawberry(gx) { | |
gx.beginPath(); | |
gx.moveTo(100, 100); | |
gx.lineTo(50, 150); | |
gx.lineTo(350, 150); | |
gx.lineTo(300, 100); | |
gx.moveTo(100, 100); | |
gx.fillStyle = "green"; | |
gx.fill(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment