Instantly share code, notes, and snippets.

🥰

# Amit Patel redblobgames

🥰
Created April 29, 2023 23:19
Three-Rhombus storage of a hex map

Reddit user /u/GavrielBA is using three rhombuses to store a hexagon-shaped map

Last active October 21, 2022 23:58
C# distance test, are Abs, Pow, or Sqrt slow? Yes - Pow(v,2) is much slower than v*v
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);
Last active September 30, 2022 16:42 — forked from HarryStevens/.block
Voronoi Jiggle
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
Created June 2, 2022 04:37
Tree generator I wrote in 2011 - but it's for Flash
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;
Created May 10, 2022 16:21
sfc32 random number generator, typescript
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() {
Created March 22, 2022 02:16
for loop comparison - probably poor benchmarking on my part
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, }); }
Last active November 27, 2021 17:40
Hyphen rendering messed up on my machine
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

Last active January 31, 2022 23:09
My note taking setup in emacs
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.
Last active November 19, 2022 17:50
my journal code
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-diary.el --- ;;; Commentary: ;; My daily diary, inspired by org-journal, but customized for my needs. ;; ;; My keybindings: H-j to open the diary file (global binding), then ;; H-j to add an entry (local binding). C-c C-b, C-c C-f to move days ;; (like org-journal). H-i to search previous headings for completion, ;; so that I can reuse headings and then analyze them.
Created November 5, 2020 17:22
Experiment: Legion ECS vs using Rust enum + pattern matching
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
 use legion::*; use rltk::{GameState, Rltk, VirtualKeyCode, RGB}; use std::cmp::{max, min}; mod map; pub use map::*; struct Player {} #[derive(PartialEq, Copy, Clone)]