Reddit user /u/GavrielBA is using three rhombuses to store a hexagon-shaped map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function clamp(x, lo, hi) { return x < lo ? lo : x > hi ? hi : x; } | |
function lerp(a, b, t) { return a * (1-t) + b * t; } | |
function unlerp(a, b, t) { return (t - a) / (b - a); } | |
function rescale(v, from_lo, from_hi, to_lo, to_hi) { return lerp(to_lo, to_hi, unlerp(from_lo, from_hi, v)); } | |
function mod(a, b) { return (a % b + b) % b; } | |
function radiansToDegrees(radians) { return 180 / Math.PI * radians; } | |
function linearstep(a, b, t) { return clamp(unlerp(a, b, t), 0, 1); } | |
function smoothstep(a, b, t) { let x = linearstep(a, b, t); return 3 * x**2 - 2 * x**3; } | |
function randRange(lo, hi) { return Math.floor(Math.random() * (hi-lo)) + lo; } | |
function randInt(lo, hi) { return randRange(lo, hi+1); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This is based on the example code from | |
* https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications | |
*/ | |
const exampleSocket = new WebSocket("ws://localhost:9999"); | |
function send(msg) { | |
document.querySelector("#send").textContent += msg + "\n"; | |
exampleSocket.send(msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Numerics; | |
static bool InDistance1(Vector2 pos1, Vector2 pos2, float maxDistance) { | |
var distance = Math.Sqrt(Math.Pow(Math.Abs(pos2.X - pos1.X), 2) + Math.Pow(Math.Abs(pos2.Y - pos1.Y), 2)); | |
return distance <= maxDistance; | |
} | |
static bool InDistance2(Vector2 pos1, Vector2 pos2, float maxDistance) { | |
var distanceSquared = (pos2.X - pos1.X) * (pos2.X - pos1.X) + (pos2.Y - pos1.Y) * (pos2.Y - pos1.Y); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Draw simple trees | |
// Author: amitp@cs.stanford.edu | |
// License: MIT | |
// TODO: read http://procworld.blogspot.com/2011/04/tree-bits.html | |
// TODO: read http://procworld.blogspot.com/2011/05/mango-sequoia-baobab.html | |
package { | |
import flash.display.*; | |
import flash.geom.Point; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SFC32 random number generator, public domain code adapted | |
// from https://github.com/bryc/code/blob/master/jshash/PRNGs.md | |
function PRNG(seed: number): { | |
nextInt(): number; | |
nextFloat(): number; | |
getState(): number[]; | |
setState(state: number[]): void | |
} { | |
let a = 0, b = seed, c = 0, d = 1; | |
function sfc32() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
let array = []; | |
for (let i = 0; i < 10000000; ++i) { | |
array.push({ | |
a: i, | |
b: i / 2, | |
r: 0, | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<style> | |
p { | |
max-width: 30em; | |
hyphens: auto; -webkit-hyphens: auto; | |
font-family: Arial; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; my-notes.el --- | |
;;; Commentary: | |
;; My notes, inspired by org-roam, but built on other packages I already use. | |
;; | |
;; 1. Capture into a queue (org-capture) | |
;; 2. Review queue (org-agenda) | |
;; 3. Find note (find-file in folder). | |
;; 4. Make new note. Fill with title, date. |
NewerOlder