Instructions:
- Copy and paste the
server.js
into a new folder calledgenart
or whatever - Run
npm init -y
to generate apackage.json
- Install the dependencies:
npm install body-parser openai express canvas dotenv
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; |
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 */ | |
} |
<!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; |
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).
One analogy I can think of might be a network of floating vending machines. You s
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 = { |
This is a canvas-sketch demo that can render an image with WebGPU in both the browser and deno.
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.
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:
Using data and code from: https://graphics.geometrian.com/research/spectral-primaries.html
See their reference implementation for details (MIT license): https://github.com/geometrian/simple-spectral
This converts sRGB triplet into spectral reflectance, then combines two curves with weighted geometric mean to produce a "mixed" colour.