ujs/src/js/scene.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-02-16 00:04:40 +03:00
import { Pointer } from './pointer.js';
export class Scene {
2023-04-06 14:44:41 +03:00
constructor(width, height) {
this.init(width, height);
2023-02-16 00:04:40 +03:00
}
2023-04-06 14:44:41 +03:00
init = async (width, height) => {
2023-02-16 00:04:40 +03:00
this.canvas = document.querySelector('canvas');
this.context = this.canvas.getContext('2d');
2023-04-06 14:44:41 +03:00
this.setScreenSize(width, height);
2023-02-16 00:04:40 +03:00
}
2023-04-06 14:54:58 +03:00
#clearCanvas() {
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
}
2023-02-16 00:04:40 +03:00
run() {
2023-04-06 14:44:41 +03:00
// clear canvas
2023-04-06 14:54:58 +03:00
this.#clearCanvas();
2023-04-06 14:52:58 +03:00
// fill canvas
this.context.fillStyle = '#523c4e';
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
// draw border
this.context.strokeStyle = '#8bd0ba';
this.context.lineWidth = 1;
this.context.strokeRect(5, 5, this.canvas.width - 10, this.canvas.height - 10);
// draw rect in center
this.context.fillStyle = '#d44e52';
this.context.fillRect(this.canvas.width / 2 - 50, this.canvas.height / 2 - 50, 100, 100);
2023-02-16 00:04:40 +03:00
}
2023-04-06 14:44:41 +03:00
setScreenSize(w, h) {
2023-02-16 00:04:40 +03:00
this.canvas.width = w;
this.canvas.height = h;
}
}