This file contains hidden or 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
| const std = @import("std"); | |
| const wasm = @import("wasm-api"); | |
| const dom = @import("wasm-api-dom"); | |
| // expose thi.ng/wasm-api core API (incl. panic handler & allocation fns) | |
| pub usingnamespace wasm; | |
| // main entry point | |
| export fn start() void { | |
| init() catch |e| @panic(@errorName(e)); |
This file contains hidden or 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
| import { epoch, int, parseCSV, type CSVRecord, type ColumnSpecs } from "@thi.ng/csv"; | |
| import { defFormat, months } from "@thi.ng/date"; | |
| import { readText, writeText } from "@thi.ng/file-io"; | |
| import { serialize } from "@thi.ng/hiccup"; | |
| import { svg } from "@thi.ng/hiccup-svg"; | |
| import { closedOpen } from "@thi.ng/intervals"; | |
| import { split } from "@thi.ng/strings"; | |
| import { comp, filter, push, transduce } from "@thi.ng/transducers"; | |
| import { | |
| barPlot, dataBounds, dataMaxLog, |
This file contains hidden or 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
| import { readJSON, writeText } from "@thi.ng/file-io"; | |
| import { XML_PROC, serialize } from "@thi.ng/hiccup"; | |
| // source path of the Google Takeout (GT) places | |
| const path = "/Downloads/Takeout/Maps (your places)/Saved Places.json"; | |
| // load GT places | |
| const places = readJSON(path).features; | |
| // FYI: partial structure of a GT place |
This file contains hidden or 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
| import { HAVERSINE_LATLON } from "@thi.ng/distance"; | |
| import { kmeans, meansLatLon } from "@thi.ng/k-means"; | |
| // 20 world cities, sorted alphabetically | |
| // data sourced from: | |
| // https://github.com/OpenDataFormats/worldcities/blob/master/src/data/cities.json | |
| const cities = [ | |
| { id: "anchorage", latlon: [61.21806, -149.90028] }, | |
| { id: "berlin", latlon: [52.52437, 13.41053] }, | |
| { id: "boston", latlon: [42.35843, -71.05977] }, |
This file contains hidden or 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
| // $ node | |
| // Welcome to Node.js v20.5.1. | |
| // Type ".help" for more information. | |
| const { barChartHStr, lineChartStr } = await import("@thi.ng/text-canvas"); | |
| const { adsr, osc, modOsc, rect, saw, sin, tri } = await import("@thi.ng/dsp"); | |
| // display line plot of 100 samples from an amplitude-modulate sine oscillator | |
| console.log(lineChartStr(20, modOsc(sin, 0.01, 0, osc(sin, 0.2)).take(100))); | |
| // ╭╮ ╭╮ ╭╮ ╭╮ |
This file contains hidden or 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
| import { FORMAT_MD, suite } from "@thi.ng/bench"; | |
| import { range } from "@thi.ng/transducers"; | |
| const testForIndexFwd = (src: number[]) => { | |
| let m = 0; | |
| for (let i = 0, n = src.length; i < n; i++) m += src[i]; | |
| return m; | |
| }; | |
| const testForIndexRev = (src: number[]) => { |
This file contains hidden or 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
| import { sortByCachedKey } from "@thi.ng/arrays"; | |
| import { analog, lch, srgb, swatchesH } from "@thi.ng/color"; | |
| import { asRGB, type LCHTheme, type RGBTheme } from "@thi.ng/color-palettes"; | |
| import { compareNumAsc } from "@thi.ng/compare"; | |
| import { serialize } from "@thi.ng/hiccup"; | |
| import { svg } from "@thi.ng/hiccup-svg"; | |
| import { SYSTEM } from "@thi.ng/random"; | |
| import { map, mean, pluck, range } from "@thi.ng/transducers"; | |
| import { comparator3 } from "@thi.ng/vectors"; | |
| import { writeFileSync } from "fs"; |
This file contains hidden or 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
| export type FxParamType = | |
| | "number" | |
| | "bigint" | |
| | "boolean" | |
| | "color" | |
| | "string" | |
| | "select"; | |
| interface FxParamBigintOpts { | |
| min?: number | bigint; |
This file contains hidden or 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
| import { parseCSVSimple } from "@thi.ng/csv"; | |
| import { readText } from "@thi.ng/file-io"; | |
| import { XsAdd, pickRandom } from "@thi.ng/random"; | |
| import { split } from "@thi.ng/strings"; | |
| import { | |
| comp, | |
| distinct, | |
| map, | |
| mapcat, | |
| push, |
This file contains hidden or 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
| rect(100) | |
| // Rect { pos: [ 0, 0 ], attribs: undefined, size: [ 100, 100 ] } | |
| rect([100, 200], 100) | |
| // Rect { pos: [ 100, 200 ], attribs: undefined, size: [ 100, 100 ] } | |
| rect([100, 200], [10, 20]) | |
| // Rect { pos: [ 100, 200 ], attribs: undefined, size: [ 10, 20 ] } | |
| rectFromCentroid([100, 200], 100) |