Skip to content

Instantly share code, notes, and snippets.

View Luftare's full-sized avatar

Ilmari Koskinen Luftare

View GitHub Profile
class DotComment {
constructor() {
this.comment = '';
const lowerCaseAlphabets = 'abcdefghiklmnopqrstvxyzåäö'.split('');
const specialCharacters = '_'.split('');
const upperCaseAlphabets = lowerCaseAlphabets.map(char =>
char.toUpperCase()
);
const characters = [
@Luftare
Luftare / View.js
Last active November 9, 2017 18:34
html canvas rendering class to handle virtual camera and rotation
class View {
constructor({
canvas = document.querySelector("canvas"),
imageNames = [],
cameraAnchor = new Vector(0, 0),
cameraPosition = new Vector(0, 0),
cameraAngle = 0,
cameraScale = 1,
cameraHeight = 1000,
cameraZoom = 1,
@Luftare
Luftare / fx.js
Created October 29, 2017 08:12
html canvas fx component
const fx = {
flashCounter: 0,
flashDamp: 10,//increase to make flash faster, decrease for longer flash
flashColor: "#fff",
shakeCounter: 0,
shakeAmplitude: 20,
shakeDamp: 5,//increse to make shake shorter, decrease to shake longer
shakeSpeed: 0.1,
shake(amount = 1) {
this.shakeCounter = amount;
@Luftare
Luftare / Input.js
Created October 29, 2017 08:06
Input class to capture keyboard and mouse events.
class Input {
constructor(el = document) {
this.keys = [];
this.mouse = [];
this.mousemoveHandlers = [];
this.mousedownHandlers = [];
this.mouseupHandlers = [];
document.addEventListener("keydown", e => {
this.keys[e.key] = true;
@Luftare
Luftare / drawImage.js
Created October 29, 2017 07:58
Draw image rotated and scaled on html canvas element
function drawImage(ctx, img, x, y, angle = 0, scale = 1){
ctx.save();
ctx.translate(x + img.width * scale / 2, y + img.height * scale / 2);
ctx.rotate(angle);
ctx.translate(- x - img.width * scale / 2, - y - img.height * scale / 2);
ctx.drawImage(img, x, y, img.width * scale, img.height * scale);
ctx.restore();
}
@Luftare
Luftare / get.js
Last active October 25, 2017 18:19
/*
Minimal AJAX get request method to fetch data. Example usage:
get('example.com/api/products/123')
.then(product => console.log(product.name))
*/
function get(url) {
return new Promise(res => {
let xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = () => {
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) res(JSON.parse(xmlHttp.responseText));