Skip to content

Instantly share code, notes, and snippets.

View mattdesl's full-sized avatar
👋

Matt DesLauriers mattdesl

👋
View GitHub Profile
function fractalNoise(x, y, frequency, octaves, persistence = 0.5, lacunarity = 2) {
let total = 0;
let amplitude = 1;
let maxValue = 0; // Used for normalizing result to 0.0 - 1.0
for (let i = 0; i < octaves; i++) {
total += noise2D(x * frequency, y * frequency) * amplitude;
maxValue += amplitude;
amplitude *= persistence;
frequency *= lacunarity;
@mattdesl
mattdesl / prng.js
Created August 2, 2023 12:00
MIT Licensed — seedable PRNG using xorshift 128 bit + djb2 hash function
const djb2 = (() => {
// http://www.cse.yorku.ca/~oz/hash.html
const _uint32 = new Uint32Array(1);
return function djb2(str) {
_uint32[0] = 5381;
for (let i = 0; i < str.length; i++) {
const c = str.charCodeAt(i);
const h = _uint32[0];
_uint32[0] = (h << 5) + h + c; /* hash * 33 + c */
}
@mattdesl
mattdesl / README.md
Last active August 9, 2023 03:44
draw HTML5 canvas with voice commands and GPT-3.5

Voice Coding with iOS Shortcuts + Node.js

Instructions:

  1. Copy and paste the server.js into a new folder called genart or whatever
  2. Run npm init -y to generate a package.json
  3. Install the dependencies:
npm install body-parser openai express canvas dotenv
@mattdesl
mattdesl / iframe.html
Created June 24, 2023 14:53
test iframe gesture
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="”viewport”"
content="”width"
="device-width,"
initial-scale="1.0,"
maximum-scale="1.0,"
// Static artwork
const randomRange = (min, max) => Math.random() * (max - min) + min;
export default ({ width, height, data }) => {
const baseHue = Math.random() * 360;
const newColor = () => {
const hue = baseHue + randomRange(-1, 1) * 5;
const sat = 50 + randomRange(-1, 1) * 10;

"the cloud"

I wish we had real cloud computers. I want to be able to write some code and deploy it to the ether, without having to maintain it. If other people find the program useful, they can tap in and run my code without me having to manage the application's uptime, bandwidth, and costs. The less control I have over it, the better. In fact, I'd love if the mere act of uploading the program also relinquishes it from my control, placing the burden on the users who will operate and use it. And, importantly, I'd like this system to be a web primitive—something that lives in a shared and open spec, like the way that HTTPS and HTML works, rather than relying on a single private company to manage everything (*cough* Amazon).

Midjourney: old computers flying in the sky

vending machines in the sky

One analogy I can think of might be a network of floating vending machines. You s

@mattdesl
mattdesl / grid.js
Created May 7, 2023 09:12
grid tiles sketch code
export function pluginGrid(fn) {
return (props) => {
const { context, width, height, data = {} } = props;
const { background = "white" } = data;
const cells = gridTiles(width, height, data).map((tile) => {
context.save();
context.translate(tile.x, tile.y);
const cellProps = {

WebGPU in Deno and the browser (with canvas-sketch)

This is a canvas-sketch demo that can render an image with WebGPU in both the browser and deno.

requirements

This requires deno 1.8 or higher (tested on 1.31.3) and a recent version of node/npm to install canvas-sketch-cli. If you want to run the browser version, you'll need a browser with WebGPU support, which is most likely going to be Chrome Canary with WebGPU enabled.

graphics toolkit wishlist

Specifically for 2D graphics and art. Not ideally suited for real-time purposes.

Hardware acceleration is not strictly necessary but would be ideal for faster iteration & feedback loops.

Main features:

  • Works on the Web (either pure JS or compiles to WASM)
  • Works outside of the Web (either Nodejs or native)