0.1.7 • Published 4 years ago

graphical-engine v0.1.7

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

graphical-engine

A simple 2D drawing library to ease the use of the HTML5 Canvas API. Made with Typescript.

Table of contents

  1. Installation
  2. Usage
  3. Documentation
  4. License

Installation

Open a command prompt or terminal and run npm install graphical-engine or yarn add graphical-engine

Usage

Along with the <script> tag/s containing your bundled code, you will need a canvas element with an id of #canvas. You can use the following HTML template for new projects:

<!DOCTYPE html>
<html>
	<head>
		<title>graphical-engine Example</title>
	</head>
	<body>
		<canvas id="canvas"></canvas>
		<script src="bundle.js"></script>
	</body>
</html>

Documentation

  1. Drawing Methods
  2. Utility Methods
  3. Globals
  4. Utilities

Drawing Methods

background(width, height, color)

stroke(loc1, loc2, color, width?)

circle(loc, radius, color, fill, width?)

arc(loc, radius, color, startAngle, endAngle, fill, width?)

rect(loc1, loc2, color, fill, width?)

triangle(loc1, loc2, loc3, color, fill, width?)

Utility Methods

clear()

  • description: * This function simply calls background(), except the arguments are always the current canvas width and height, and the color used in the last background()call. It is used to clear the canvas.

center(absolute?)

setup(callback)

update(callback)

Globals

canvas - [HTMLCanvasElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement)

The canvas element.

ctx - [CanvasRenderingContext2D](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D)

The 2D canvas rendering context.

CANVAS_WIDTH - [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)

The current width of the canvas element.

CANVAS_HEIGHT - [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)

The current height of the canvas element.

Utilities

class: Vector2

A 2D vector class that contains useful methods for creating and manipulating vectors.

Properties:

Methods:

  • static Vector2.from(v)
    • Creates a new vector from the coordinates of the supplied vector.
    • param v - <Vector2> A vector.
    • returns <Vector2> - A new vector.

class: Color

An RGB/hex color class that contains useful methods for translating color formats.

Properties:

Methods:

License

This project and all of its code are under the permissive MIT license. You can read more here: LICENSE

1.1.5-alpha

4 years ago

0.1.7

4 years ago

1.1.4-alpha

4 years ago

0.1.6

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago