Skip to content

Instantly share code, notes, and snippets.

@tabone
tabone / shadowcasting.js
Created July 30, 2024 15:18 — forked from 370417/shadowcasting.js
Symmetric recursive shadowcasting
/**
* Recursive shadowcasting algorithm.
* This algorithm creates a field of view centered around (x, y).
* Opaque tiles are treated as if they have beveled edges.
* Transparent tiles are visible only if their center is visible, so the
* algorithm is symmetric.
* @param cx - x coordinate of center
* @param cy - y coordinate of center
* @param transparent - function that takes (x, y) as arguments and returns the transparency of that tile
* @param reveal - callback function that reveals the tile at (x, y)
@tabone
tabone / main.js
Created October 24, 2023 16:27
Chiliz Technical Challege
/*
* Your program must print string with the number of years and months and the total number of days between the dates.
* Dates are provided in dd.mm.yyyy format.
* You are not allowed to plug in JS libraries such as moment.js or date-fns directly into the code. All code need to be written in this file.
*
* Result must be shown as a string in years, months and total days. If years or months are 0, then it should not be displayed in the output.
*
* Example:
* Input: ['01.01.2000', '01.01.2016']
* Output:
@tabone
tabone / index.js
Created April 11, 2020 08:05
Line Gradient
function newLineGradient (info = {}) {
const blur = info.blur
const size = info.size - 1
const minCoordBlur = blur
const maxCoordBlur = size - blur
return function getValue (coord = Infinity) {
if (coord <= minCoordBlur) return 0
if (coord >= maxCoordBlur) return 1
function newFractalNoise (info) {
const {
noise,
octaves = 1,
amplitude = 1.0,
frequency = 1.0,
persistence = .5
} = info
return function getFractalNoise (x, y) {
var TWO_PI = 2 * Math.PI;
function processOptions(options) {
return {
amplitude: typeof options.amplitude === "number" ? options.amplitude : 1.0,
frequency: typeof options.frequency === "number" ? options.frequency : 1.0,
octaves: typeof options.octaves === "number" ? Math.floor(options.octaves) : 1,
persistence: typeof options.persistence === "number" ? options.persistence : 0.5
};
}
function makeCuboid(width, height, depth, noise3, options) {
@tabone
tabone / index.js
Last active March 3, 2020 17:14
Compiled version of open-simplex-noise - https://www.npmjs.com/package/open-simplex-noise
var NORM_2D = 1.0 / 47.0;
var NORM_3D = 1.0 / 103.0;
var NORM_4D = 1.0 / 30.0;
var SQUISH_2D = (Math.sqrt(2 + 1) - 1) / 2;
var SQUISH_3D = (Math.sqrt(3 + 1) - 1) / 3;
var SQUISH_4D = (Math.sqrt(4 + 1) - 1) / 4;
var STRETCH_2D = (1 / Math.sqrt(2 + 1) - 1) / 2;
var STRETCH_3D = (1 / Math.sqrt(3 + 1) - 1) / 3;
var STRETCH_4D = (1 / Math.sqrt(4 + 1) - 1) / 4;
var base2D = [
@tabone
tabone / index.js
Last active March 3, 2020 19:14
Box Gradient
function newGradient (info = {}) {
const blur = info.blur
const size = info.size - 1
const minCoordBlur = blur
const maxCoordBlur = size - blur
return function getValue (x = Infinity, y = Infinity) {
const { coord } = [{
coord: x,
@tabone
tabone / index.js
Created March 13, 2019 21:57
OAuth2 Server
{
"name": "oauth",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"keywords": [],
"author": "Luca Tabone <taboneluca3@gmail.com>",
@tabone
tabone / vcs
Last active November 26, 2024 08:12
{
"files.eol": "\n",
"editor.tabSize": 2,
"window.zoomLevel": 1,
"git.autofetch": true,
"editor.rulers": [ 80 ],
"editor.cursorStyle": "block",
"window.commandCenter": false,
"editor.minimap.enabled": false,
"files.trimFinalNewlines": true,
@tabone
tabone / config.json
Created February 13, 2018 21:36
Atom.io
"*":
core:
telemetryConsent: "no"
editor:
fontSize: 17
invisibles: {}
scrollPastEnd: true
showInvisibles: true
softWrap: true
tabType: "soft"