Skip to content

Instantly share code, notes, and snippets.

// add any configs you like
export default {
value:0.5,
autoSave: false,
};
@yiwenl
yiwenl / Bezier - 2D
Last active September 24, 2023 16:46
Bezier Curve with gl-matrix
import { vec2 } from "gl-matrix";
export const bezier = (mPoints, t) => {
if (mPoints.length === 2) {
const p = vec2.create();
vec2.lerp(p, mPoints[0], mPoints[1], t);
return p;
}
const a = [];
@yiwenl
yiwenl / doTrianglesIntersect.js
Last active September 5, 2023 20:21
Triangle intersection check
// Triangle format: [[x, y], [x, y], [x, y]]
function doTrianglesIntersect(triangle1, triangle2) {
function doEdgesIntersect(edge1, edge2) {
// Check if two line segments (edges) intersect
const [x1, y1] = edge1[0];
const [x2, y2] = edge1[1];
const [x3, y3] = edge2[0];
const [x4, y4] = edge2[1];
@yiwenl
yiwenl / sort-chars.js
Last active December 8, 2023 14:16
Sorting characters with number of transparent pixels
// Create a canvas element
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
canvas.width = 64;
canvas.height = 64;
// Function to calculate non-transparent pixels
function countNonTransparentPixels(character) {
// Clear the canvas
context.clearRect(0, 0, canvas.width, canvas.height);