Skip to content

Instantly share code, notes, and snippets.

View selfsame's full-sized avatar

Joseph Parker selfsame

  • Clover Food Lab
View GitHub Profile

Generating Procedural Game Worlds with Wave Function Collapse

Wave Function Collapse (WFC) by @exutumno is a new algorithm that can generate procedural patterns from a sample image. It's especially exciting for game designers, letting us draw our ideas instead of hand coding them. We'll take a look at the kinds of output WFC can produce and the meaning of the algorithm's parameters. Then we'll walk through setting up WFC in javascript and the Unity game engine.

sprites

The traditional approach to this sort of output is to hand code algorithms that generate features, and combine them to alter your game map. For example you could sprinkle some trees at random coordinates, draw roads with a brownian motion, and add rooms with a Binary Space Partition. This is powerful but time consuming, and your original vision can someti

@selfsame
selfsame / snip.md
Last active February 10, 2024 17:32
compute volume of three.js ConvexHull

A bit of js that computes the volume of a ConvexHull (or any mesh if you iterate the faces making tetrahedrons with the centerpoint)

import {Vector3} from 'three'
import {ConvexHull} from 'three/examples/jsm/math/ConvexHull.js'

// via https://stackoverflow.com/questions/9866452/calculate-volume-of-any-tetrahedron-given-4-points
function determinant_3x3(m){
    return (m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) -
            m[1][0] * (m[0][1] * m[2][2] - m[0][2] * m[2][1]) +
@selfsame
selfsame / computers.ni
Created October 2, 2018 23:55
computers.ni
"dungeon planet" by Joseph Parker
Book 1 - Rules
Chapter 1 - Computers
An operating system is a kind of value. The operating systems are linux.
A computer is a kind of device. Understand "computer" as computer.
A computer has a text called power_up_text.
//single file version of https://github.com/kchapelier/wavefunctioncollapse
function randomIndice (array, r) {
var sum = 0,
i,
x;
for (i = 0; i < array.length; i++) {
sum += array[i];
}
(var _ts {})
(fn lerp [a b r] (+ a (* (- b a) r)))
(fn vlerp [a b r] (v.vadd a (v.vmul (v.vsub b a) r)))
(fn powf [n] (fn [v] (^ v n)))
(fn tween [o p v d _]
(let [_ (or _ {})
t {:o o :p p :v v :d d :s d
:f _.f
(var _ts {})
(fn lerp [a b r] (+ a (* (- b a) r)))
(fn powf [n] (fn [v] (^ v n)))
(fn tween [o p v d _]
(let [_ (or _ {})
t {:o o :p p :v v :d d :s d
:f _.f
:l (or _.l lerp)
:ei (or _.ei _.e)
(defn self-serve-info [state]
(let [items (retail-cart-items)
kitchen-stuff? (< (count items) (count (keys @CART)))]
[:div#checkout.retail
[:div#content
[:h1 "Self Serve Items"]
[:h2 "please pick up the following items from the Fridge or the Retail Shelf:"]
[:div.group
(doall
@selfsame
selfsame / arcadia.compiler.clj
Created May 4, 2019 16:58
arcadia godot compiler ns
(ns arcadia.compiler
(:use
arcadia.core)
(:require
[clojure.spec.alpha :as s]
clojure.string
[arcadia.internal.spec :as as]
[arcadia.config :as config]))
(defn aot-namespaces [path nss]
@selfsame
selfsame / aoc.apl
Last active December 14, 2018 05:41
#day 1
+/INPUT
{1↑{((⍵⍳⍵)≠⍳⍴⍵)/⍵}+⍀0,1000000⍴⍵}INPUT
#day 2
⍝ part 1 dyalog
@selfsame
selfsame / rnn.py
Created September 19, 2018 19:26
textgenrnn utility scrips
import sys, os, re
import pprint
from util import *
import re
from textgenrnn import textgenrnn
textgen = textgenrnn()
def gen(cnt="10", temp="1.0"):
textgen.generate(int(cnt), temperature=float(temp))