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
// $ 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 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 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 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 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 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) |
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
/* | |
* Copyright (c) 2022 Karsten Schmidt | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* |
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
import { int, parseCSVSimple } from "@thi.ng/csv"; | |
import { readText } from "@thi.ng/file-io"; | |
import { pickRandom } from "@thi.ng/random"; | |
import { split } from "@thi.ng/strings"; | |
import { | |
comp, | |
distinct, | |
mapcat, | |
push, | |
repeat, |
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
import { suite } from "@thi.ng/bench"; | |
const w = 640; | |
const h = 480; | |
const idata = new ImageData(w, h); | |
// exposed u8clampedarray | |
const u8 = idata.data; | |
// rewrap same memory as u32 | |
const u32 = new Uint32Array(u8.buffer); |
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
#!/bin/sh | |
zig build-lib -O ReleaseSmall -target wasm32-freestanding -dynamic --strip \ | |
--pkg-begin wasmapi ../../node_modules/@thi.ng/wasm-api/include/wasmapi.zig --pkg-end \ | |
--pkg-begin dom ../../node_modules/@thi.ng/wasm-api-dom/include/dom.zig --pkg-end \ | |
src/main.zig | |
# optional post processing & optimization | |
wasm-opt main.wasm -o main.wasm -O3 |