Skip to content

Instantly share code, notes, and snippets.

@jetp250
jetp250 / GreedyMeshing.java
Last active November 8, 2021 22:15
Greedy meshing in Java
// A variant of greedy meshing for 2D tile grids.
//
// As is, the algorithm treats the grid as binary: empty or non-epmty. No quads are emitted for non-empty tiles.
// It can be extended to multiple types by keeping track of the current tile type
// and 1) treating a change of type as an obstacle and 2) not skipping over the found 'obstacle'.
//
// The algorithm has the following guarantees:
// - Each tile in the chunk is accessed exactly once.
// - None of the returned quads have a width or height of 0.
// - It can never return more quads than a naive mesher would.
@jetp250
jetp250 / HookesLaw.java
Created August 14, 2021 10:28
An implementation of Hooke's law in Processing (Java)
// If this looks weird, it's because the Java used in Processing sketches is a bit different.
// Wikipedia considers it its own language, even
import java.util.List;
import java.util.ArrayList;
class Atom {
PVector pos;
PVector velocity;
@jetp250
jetp250 / CatmullRomSpline.java
Created August 2, 2021 11:27
Stateful (uniform) Catmull-Rom spline implementation in Processing (Java)
public final class CatmullRomSpline implements Iterator<PVector> {
private final PVector[] points;
private int pointIdx;
private PVector P0, P1, P2, P3;
private float t;
private final float tInc;
private boolean hasNext;