-
Notifications
You must be signed in to change notification settings - Fork 0
/
BETA.d.ts
173 lines (106 loc) · 5.2 KB
/
BETA.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
declare namespace BETA
{
function assert(assertion: boolean, message?: string): void;
function isNumber(val: any): boolean;
function mod(x: number, y: number): number;
function clamp(val: number, a: number, b: number): number;
function randNum(a: number, b: number): number;
function randInt(a: number, b: number): number;
function randElement<T>(arr: T[]): T;
//------------COLOR FUNCTIONS-----------\\
class Color
{
r: number;
g: number;
b: number;
a: number;
toString(): string;
}
function rgba(red: number, green: number, blue: number, alpha: number): Color;
function rgb(red: number, green: number, blue: number): Color;
function hsla(hue: number, saturation: number, lightness: number, alpha: number): Color;
function hsl(hue: number, saturation: number, lightness: number): Color;
function hsva(hue: number, saturation: number, value: number, alpha: number): Color;
function hsv(hue: number, saturation: number, value: number): Color;
function hwba(hue: number, whiteness: number, blackness: number, alpha: number): Color;
function hwb(hue: number, whiteness: number, blackness: number): Color;
//------------VECTOR FUNCTIONS------------\\
interface Vector
{
x: number;
y: number;
}
function vector(x: number, y: number): Vector;
function v(x: number, y: number): Vector;
function vCopy(v: Vector): Vector;
function vStringify(v: Vector): string;
function vEquals(v1: Vector, v2: Vector): boolean;
function vAdd(v1: Vector, v2: Vector): Vector;
function vSubtract(v1: Vector, v2: Vector): Vector;
function vScale(v1: Vector, v2: Vector): Vector;
function vDot(v1: Vector, v2: Vector): Vector;
function vComplexMult(v1: Vector, v2: Vector): Vector;
function vScalarMult(v: Vector, s: number): Vector;
function vScalarDiv(v: Vector, s: number): Vector;
function vMagnitude(v: Vector): number;
function vNormalize(v: Vector): Vector;
function vAngle(vec: Vector): number;
function vFromPolar(radius: number, angle: number): Vector;
function vDistance(v1: Vector, v2: Vector): number;
function vGridDist(v1: Vector, v2: Vector): number;
function vRotate(vec: Vector, pivot: Vector, angle: number): Vector;
//------------IMAGE FUNCTIONS-------------\\
function loadImage(url: string): HTMLImageElement;
function waitForImgLoad(callback: () => any): void;
//------------CANVAS INTERFACE------------\\
type CanvasStyle = Color | string | CanvasGradient | CanvasPattern;
class CanvasRenderer
{
id: string;
canvas: HTMLCanvasElement;
context: CanvasRenderingContext2D;
width: number;
height: number;
size: Vector;
//Configuration
resize(x: number, y: number): void;
resizeByVector(vector: Vector): void;
resizeToMax(): void;
translate(x: number, y: number): void;
translateByVector(vector: Vector): void;
scale(x: number, y: number): void;
scaleByVector(vector: Vector): void;
rotate(degrees: number): void;
rotateRad(radians: number): void;
save(): void;
restore(): void;
//Rendering
line(posA: Vector, posB: Vector, thickness: number, color: CanvasStyle): void;
fillCircle(pos: Vector, radius: number, color: CanvasStyle): void;
lineCircle(pos: Vector, radius: number, thickness: number, color: CanvasStyle): void;
fillSector(pos: Vector, radius: number, startAngle: number, endAngle: number, color: CanvasStyle): void;
lineSector(pos: Vector, radius: number, startAngle: number, endAngle: number, thickness: number, color: CanvasStyle): void;
arc(pos: Vector, radius: number, startAngle: number, endAngle: number, thickness: number, color: CanvasStyle): void;
fillRect(pos: Vector, size: Vector, color: CanvasStyle): void;
lineRect(pos: Vector, size: Vector, thickness: number, color: CanvasStyle): void;
fillPolygon(posArray: Vector[], color: CanvasStyle): void;
linePolygon(posArray: Vector[], thickness: number, color: CanvasStyle): void;
clear(): void;
clearRect(pos: Vector, size: Vector): void;
fill(color: CanvasStyle): void;
drawImage(img: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement, pos: Vector, size?: Vector): void;
text(pos: Vector, text: string, font: string, size: number, color: CanvasStyle): void;
getTextWidth(text: string, font: string, size: number): number;
}
function getRenderer(id: string): CanvasRenderer;
//------------ANIMATION SYSTEM------------\\
function animate(callback: (deltaTime: number) => any): void;
function stopAnimation(): void;
//-------------INPUT HANDLING-------------\\
function initInput(): void;
function isButtonDown(button: string): boolean;
type ButtonEventHandler = (event: MouseEvent | KeyboardEvent) => any;
function onButtonDown(button: string, callback: ButtonEventHandler): void;
function onButtonUp(button: string, callback: ButtonEventHandler): void;
function getMousePos(renderer: CanvasRenderer): Vector;
}