Skip to content

Commit 80da8a5

Browse files
committed
Updates
1 parent de69707 commit 80da8a5

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

Applications/FrostedColours

Applications/Level/Sensor.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
var horizon = document.getElementById("horizon");
1111
var ctx = horizon.getContext('2d');
1212

13-
function Graphics(element) {
13+
/**
14+
* @constructor
15+
* @param {HTMLCanvasElement | string | null} element
16+
*/
17+
function GraphicsBase(element) {
1418
/** @type {HTMLCanvasElement?} */
1519
this.canvas = (
1620
element instanceof HTMLCanvasElement
@@ -20,25 +24,42 @@ function Graphics(element) {
2024
? document.getElementById(element)
2125
: document.createElement("canvas")
2226
));
27+
28+
this.canvas.onresize = function () {
29+
var bounds = canvas.getBoundingClientRect();
30+
graphics.resize(bounds.width, bounds.height);
31+
}
32+
}
33+
34+
GraphicsBase.prototype.resize = function (width, height) {
35+
this.canvas.width = width;
36+
this.canvas.height = height;
37+
}
38+
39+
GraphicsBase.prototype.getContext = function (type) {
40+
return this.canvas.getContext();
2341
}
2442

2543
/**
26-
* @param {string | HTMLCanvasElement} elementId
44+
* @constructor
45+
* @extends {GraphicsBase}
46+
* @param {string | HTMLCanvasElement | null} element
2747
*/
2848
function Graphics2D(element) {
29-
Graphics.call(this, element);
30-
this.ctx = this.canvas.getContext("2d");
49+
GraphicsBase.call(this, element);
50+
this.ctx = this.getContext("2d");
3151
}
3252

3353
// Graphics2D.prototype.__proto__ = Graphics.prototype;
3454
// Graphics2D.constru
35-
Graphics2D.prototype = Object.create(Graphics.prototype);
36-
Graphics2D.prototype.constructor = Graphics;
55+
Graphics2D.prototype = Object.create(GraphicsBase.prototype);
56+
Graphics2D.prototype.constructor = GraphicsBase;
3757

3858
var graphics = new Graphics2D("horizon");
3959

4060
function drawHorizon(roll, pitch) {
4161
var w = horizon.width, h = horizon.height;
62+
var ctx = graphics.ctx;
4263

4364
const pixelOffset = pitch * 5;
4465

0 commit comments

Comments
 (0)