Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "litecanvas",
"version": "0.207.2",
"version": "0.208.0",
"description": "Lightweight HTML5 canvas 2D game engine suitable for small projects and creative coding. Inspired by PICO-8 and p5.js/Processing.",
"license": "MIT",
"author": "Luiz Bills <luizbills@pm.me>",
Expand Down
3 changes: 1 addition & 2 deletions samples/3d/3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ function update(dt) {
function draw() {
cls(0)

push()
translate(W / 2, H / 2)
push(W / 2, H / 2)
for (let i = 0; i < 4; i++) {
connect(i, (i + 1) % 4, projected)
connect(i + 4, ((i + 1) % 4) + 4, projected)
Expand Down
1 change: 0 additions & 1 deletion samples/mouse/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ litecanvas({
function draw() {
cls(1)

// -1
if (MX === -1) {
return text(20, 20, 'move your mouse', 2)
}
Expand Down
1 change: 0 additions & 1 deletion samples/shapes/shapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ function init() {
gap = 40
lineDashPattern = [30, 15]
lineDashOffset = 0
lineWidth = 3
types = [
() => rectfill(0, 0, size, size, 2),
() => rect(0, 0, size, size, 1),
Expand Down
127 changes: 85 additions & 42 deletions src/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 28 additions & 2 deletions types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ declare global {
* @returns the value in degrees
*/
function rad2deg(rads: number): number
/**
* Modulus (Euclidean division).
*
* Note: When `b == 0` returns `0`, rather than `NaN`.
*
* @param a dividend
* @param b divisor
* @returns the remainder
* @example
* mod(-1, 5) // => 4
* -1 % 5 // => -1
*/
function mod(a: number, b: number): number
/**
* Returns the rounded value of an number to optional precision (number of digits after the decimal point).
*
Expand Down Expand Up @@ -430,10 +443,23 @@ declare global {
context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D
): CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D
/**
* saves the current drawing style settings and transformations
* Saves the current drawing style settings and, optionally, transforms (translate/rotate/scale) the canvas.
*
* @param [translateX]
* @param [translateY]
* @param [rotation] in radians
* @param [scaleX]
* @param [scaleY]
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
*/
function push(): void
function push(
translateX?: number,
translateY?: number,
rotation?: number,
scaleX?: number,
scaleY?: number
): void
/**
* restores the drawing style settings and transformations
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/restore
Expand Down
34 changes: 30 additions & 4 deletions types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ type LitecanvasInstance = {
H: number
/** the amount of time (in seconds) since the game started */
T: number
/** The current mouse's horizontal (X) position or -1 (if the mouse was not used or detected) */
/** The current mouse's horizontal (X) position or `-1` (if the mouse was not used or detected) */
MX: number
/** The current mouse's vertical (Y) position or -1 (if the mouse was not used or detected) */
/** The current mouse's vertical (Y) position or `-1` (if the mouse was not used or detected) */
MY: number

/** MATH API */
Expand Down Expand Up @@ -53,6 +53,19 @@ type LitecanvasInstance = {
* @returns the value in degrees
*/
rad2deg(rads: number): number
/**
* Modulus (Euclidean division).
*
* Note: When `b == 0` returns `0`, rather than `NaN`.
*
* @param a dividend
* @param b divisor
* @returns the remainder
* @example
* mod(-1, 5) // => 4
* -1 % 5 // => -1
*/
mod(a: number, b: number): number
/**
* Returns the rounded value of an number to optional precision (number of digits after the decimal point).
*
Expand Down Expand Up @@ -418,10 +431,23 @@ type LitecanvasInstance = {
context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D
): CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D
/**
* saves the current drawing style settings and transformations
* Saves the current drawing style settings and, optionally, transforms (translate/rotate/scale) the canvas.
*
* @param [translateX]
* @param [translateY]
* @param [rotation] in radians
* @param [scaleX]
* @param [scaleY]
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
*/
push(): void
push(
translateX?: number,
translateY?: number,
rotation?: number,
scaleX?: number,
scaleY?: number
): void
/**
* restores the drawing style settings and transformations
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/restore
Expand Down
Loading