BlueGit

timfa raytracer

Files

raytracer / js / Canvas.js

Canvas.js

import
timfa Tim Falken · pushed by timfa · 6 years ago
155b19f9 History
Canvas.js 1.1 KiB Download Raw
1// Wrapper for some canvas drawing functions
2
3var Canvas =
4{
5 get canvas()
6 {
7 return GameWindow.canvas;
8 },
9
10 get context()
11 {
12 return GameWindow.canvasContext;
13 },
14
15 drawText: function(text, x, y, size, font, color)
16 {
17 this.context.font = font? size + 'px ' + font : size + 'px Arial';
18
19 this.context.fillStyle = color;
20 this.context.strokeStyle = color;
21 this.context.textAlign = "center";
22 this.context.textBaseline="middle";
23
24 this.context.fillText(text, x, y);
25 },
26
27 drawLine(xStart, yStart, xEnd, yEnd, color)
28 {
29 this.context.fillStyle = color;
30 this.context.strokeStyle = color;
31
32 this.context.beginPath();
33 this.context.moveTo(xStart, yStart);
34 this.context.lineTo(xEnd, yEnd);
35
36 this.context.stroke();
37 },
38
39 drawRect(xStart, yStart, xEnd, yEnd, color)
40 {
41 this.context.fillStyle = color;
42 this.context.strokeStyle = color;
43
44 this.context.beginPath();
45 this.context.fillRect(xStart, yStart, xEnd, yEnd);
46 }
47}