build-in-public-bot
Version:
AI-powered CLI bot for automating build-in-public tweets with code screenshots
387 lines • 17.6 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.WasmRasterizer = void 0;
class WasmRasterizer {
width;
height;
pixels;
themeColors;
constructor(width, height, themeColors) {
this.width = width;
this.height = height;
this.pixels = new Uint8Array(width * height * 4);
this.themeColors = themeColors;
}
hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : { r: 255, g: 255, b: 255 };
}
getThemedColor(type) {
if (!this.themeColors) {
const fallback = {
primary: '#ff6b6b',
secondary: '#4ecdc4',
accent: '#45b7d1',
background: '#2a2a2a'
};
return this.hexToRgb(fallback[type]);
}
return this.hexToRgb(this.themeColors[type]);
}
setPixel(x, y, r, g, b, a = 255) {
if (x < 0 || x >= this.width || y < 0 || y >= this.height)
return;
const idx = (y * this.width + x) * 4;
this.pixels[idx] = r;
this.pixels[idx + 1] = g;
this.pixels[idx + 2] = b;
this.pixels[idx + 3] = a;
}
renderWaveGradient() {
const time = Date.now() * 0.001;
const mouseX = 0.5;
const mouseY = 0.5;
for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
const u = x / this.width;
const v = y / this.height;
const aspect = this.width / this.height;
const uvAdjusted = { x: u * aspect, y: v };
const mouseInfluence = 0.05 * Math.sqrt(Math.pow(uvAdjusted.x - mouseX * aspect, 2) +
Math.pow(v - mouseY, 2));
const gradientPos = v + 0.2 * Math.sin(uvAdjusted.x * 1.5 + time * 0.2) - mouseInfluence;
const primaryColor = this.getThemedColor('primary');
const secondaryColor = this.getThemedColor('secondary');
const accentColor = this.getThemedColor('accent');
const bgColor = this.getThemedColor('background');
const skyTop = {
r: bgColor.r / 255 * 0.7,
g: bgColor.g / 255 * 0.7,
b: bgColor.b / 255 * 0.7
};
const skyMid = {
r: secondaryColor.r / 255 * 0.8,
g: secondaryColor.g / 255 * 0.8,
b: secondaryColor.b / 255 * 0.8
};
const horizon = {
r: accentColor.r / 255,
g: accentColor.g / 255,
b: accentColor.b / 255
};
const ground = {
r: primaryColor.r / 255 * 0.6,
g: primaryColor.g / 255 * 0.6,
b: primaryColor.b / 255 * 0.6
};
let color;
if (gradientPos > 0.7) {
const t = (gradientPos - 0.7) / 0.3;
color = {
r: skyTop.r + (skyMid.r - skyTop.r) * t,
g: skyTop.g + (skyMid.g - skyTop.g) * t,
b: skyTop.b + (skyMid.b - skyTop.b) * t
};
}
else if (gradientPos > 0.4) {
const t = (gradientPos - 0.4) / 0.3;
color = {
r: skyMid.r + (horizon.r - skyMid.r) * t,
g: skyMid.g + (horizon.g - skyMid.g) * t,
b: skyMid.b + (horizon.b - skyMid.b) * t
};
}
else {
const t = Math.max(0, Math.min(1, gradientPos / 0.4));
color = {
r: ground.r + (horizon.r - ground.r) * t,
g: ground.g + (horizon.g - ground.g) * t,
b: ground.b + (horizon.b - ground.b) * t
};
}
const variation = Math.sin(uvAdjusted.x * 10.0 + time) * 0.05;
color.r += variation;
color.g += variation * 0.4;
const dust = this.fbm(u * 3.0 + time * 0.1, v * 3.0) * 0.1;
color.r += dust;
color.g += dust * 0.9;
color.b += dust * 0.7;
const grain = this.noise(u * 500.0 + time * 10.0, v * 500.0) * 0.15;
const mouseDistance = Math.sqrt(Math.pow(u - mouseX, 2) + Math.pow(v - mouseY, 2));
const mouseGrainInfluence = this.smoothstep(0.0, 0.5, mouseDistance);
const grainAmount = grain * mouseGrainInfluence;
color.r += grainAmount;
color.g += grainAmount;
color.b += grainAmount;
const vignetteDist = Math.sqrt(Math.pow(u - 0.5, 2) + Math.pow(v - 0.5, 2)) * 1.5;
const vignette = 1.0 - this.smoothstep(0.5, 1.5, vignetteDist);
const vignetteMultiplier = 0.8 + 0.2 * vignette;
color.r *= vignetteMultiplier;
color.g *= vignetteMultiplier;
color.b *= vignetteMultiplier;
const r = Math.floor(Math.max(0, Math.min(1, color.r)) * 255);
const g = Math.floor(Math.max(0, Math.min(1, color.g)) * 255);
const b = Math.floor(Math.max(0, Math.min(1, color.b)) * 255);
this.setPixel(x, y, r, g, b);
}
}
return this.pixels;
}
renderMatrix() {
this.pixels.fill(0);
const fontSize = 10.0;
const time = Date.now() * 0.001;
for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
const u = x / this.width;
const v = y / this.height;
const gridX = Math.floor(u * this.width / fontSize);
const gridY = Math.floor(v * this.height / fontSize);
const random = this.hash(gridX + gridY * 1000.0);
const speed = random * 0.5 + 0.5;
const offset = time * speed;
const fallPosition = (gridY / (this.height / fontSize) + offset) % 1.0;
let brightness = 0.0;
const cellY = (v * this.height / fontSize) % 1.0;
if (cellY > 0.1 && cellY < 0.9) {
const charRandom = this.hash(gridX * 100.0 + Math.floor(fallPosition * 20.0));
if (charRandom > 0.5) {
brightness = 1.0 - fallPosition;
}
}
const trailLength = 0.3;
if (fallPosition < trailLength) {
brightness = Math.max(brightness, (1.0 - fallPosition / trailLength) * 0.5);
}
const primaryColor = this.getThemedColor('primary');
const secondaryColor = this.getThemedColor('secondary');
const mainColor = primaryColor;
const trailColor = secondaryColor;
const r = Math.floor((trailColor.r + (mainColor.r - trailColor.r) * brightness) * brightness);
const g = Math.floor((trailColor.g + (mainColor.g - trailColor.g) * brightness) * brightness);
const b = Math.floor((trailColor.b + (mainColor.b - trailColor.b) * brightness) * brightness);
this.setPixel(x, y, r, g, b);
}
}
return this.pixels;
}
renderHalftone() {
const time = Date.now() * 0.001;
for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
const u = x / this.width;
const v = y / this.height;
const primaryColor = this.getThemedColor('primary');
const secondaryColor = this.getThemedColor('secondary');
const bgColor = this.getThemedColor('background');
const baseGradient = 0.4 + 0.3 * this.fbm(u * 2.0, v * 2.0);
const dotScale = 20.0;
const gridU = (u * dotScale) % 1.0;
const gridV = (v * dotScale) % 1.0;
const dotDist = Math.sqrt(Math.pow(gridU - 0.5, 2) +
Math.pow(gridV - 0.5, 2));
const dotSizeVariation = 0.3 + 0.2 * this.fbm(u * 4.0 + time * 0.1, v * 4.0);
const maxDotRadius = 0.35 * dotSizeVariation;
const dotIntensity = this.smoothstep(maxDotRadius, maxDotRadius - 0.1, dotDist);
const flow = this.fbm(u * 3.0 + time * 0.3, v * 3.0 + time * 0.2) * 0.2;
const totalIntensity = Math.max(0, Math.min(1, baseGradient * 0.6 + dotIntensity * 0.8 + flow));
let r, g, b;
if (totalIntensity < 0.33) {
const t = totalIntensity * 3.0;
r = Math.floor(bgColor.r + (secondaryColor.r - bgColor.r) * t);
g = Math.floor(bgColor.g + (secondaryColor.g - bgColor.g) * t);
b = Math.floor(bgColor.b + (secondaryColor.b - bgColor.b) * t);
}
else if (totalIntensity < 0.66) {
const t = (totalIntensity - 0.33) * 3.0;
r = Math.floor(secondaryColor.r + (primaryColor.r - secondaryColor.r) * t);
g = Math.floor(secondaryColor.g + (primaryColor.g - secondaryColor.g) * t);
b = Math.floor(secondaryColor.b + (primaryColor.b - secondaryColor.b) * t);
}
else {
const t = (totalIntensity - 0.66) * 3.0;
const highlightR = Math.min(255, primaryColor.r + 40);
const highlightG = Math.min(255, primaryColor.g + 40);
const highlightB = Math.min(255, primaryColor.b + 40);
r = Math.floor(primaryColor.r + (highlightR - primaryColor.r) * t);
g = Math.floor(primaryColor.g + (highlightG - primaryColor.g) * t);
b = Math.floor(primaryColor.b + (highlightB - primaryColor.b) * t);
}
this.setPixel(x, y, r, g, b);
}
}
return this.pixels;
}
renderDisruptor() {
const time = Date.now() * 0.001;
const mouseX = 0.5;
const mouseY = 0.5;
for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
let u = x / this.width;
const v = y / this.height;
const aspect = this.width / this.height;
u = u * aspect;
const mouse = { x: mouseX * aspect, y: mouseY };
const mouseDistance = Math.sqrt(Math.pow(u - mouse.x, 2) + Math.pow(v - mouse.y, 2));
const mouseInfluence = this.smoothstep(0.5, 0.0, mouseDistance);
const t = time * 0.2;
const n1 = this.fbm(u * 1.5 + t * 0.3, v * 1.5 + t * 0.2);
const n2 = this.fbm(u * 2.5 - t * 0.2, v * 2.5 - t * 0.1);
const n3 = this.fbm(u * 0.8 + t * 0.1, v * 0.8 + t * 0.3);
let organicNoise = n1 * 0.5 + n2 * 0.3 + n3 * 0.2;
organicNoise += mouseInfluence * 0.3 * Math.sin(t * 2.0);
const pattern = this.fbm(u * (1.0 + mouseInfluence) + organicNoise * 0.2, v * (1.0 + mouseInfluence) + organicNoise * 0.2);
const brightness = 0.5 + 0.5 * pattern;
const dithered = this.dither(u, v, brightness);
const primaryColor = this.getThemedColor('primary');
const secondaryColor = this.getThemedColor('secondary');
const accentColor = this.getThemedColor('accent');
const color1 = {
r: primaryColor.r / 255 * 0.3,
g: primaryColor.g / 255 * 0.3,
b: primaryColor.b / 255 * 0.3
};
const color2 = {
r: secondaryColor.r / 255 * 0.7,
g: secondaryColor.g / 255 * 0.7,
b: secondaryColor.b / 255 * 0.7
};
const color3 = {
r: accentColor.r / 255,
g: accentColor.g / 255,
b: accentColor.b / 255
};
let finalColor;
if (dithered > 0.5) {
finalColor = color3;
}
else {
const t = organicNoise;
finalColor = {
r: color1.r + (color2.r - color1.r) * t,
g: color1.g + (color2.g - color1.g) * t,
b: color1.b + (color2.b - color1.b) * t
};
}
const pulseAmount = mouseInfluence * (0.5 + 0.5 * Math.sin(time * 3.0));
finalColor.r += 0.1 * pulseAmount;
finalColor.g += 0.2 * pulseAmount;
finalColor.b += 0.3 * pulseAmount;
const r = Math.floor(Math.max(0, Math.min(1, finalColor.r)) * 255);
const g = Math.floor(Math.max(0, Math.min(1, finalColor.g)) * 255);
const b = Math.floor(Math.max(0, Math.min(1, finalColor.b)) * 255);
this.setPixel(x, y, r, g, b);
}
}
return this.pixels;
}
dither(u, v, brightness) {
const bayer = [
0.0 / 16.0, 8.0 / 16.0, 2.0 / 16.0, 10.0 / 16.0,
12.0 / 16.0, 4.0 / 16.0, 14.0 / 16.0, 6.0 / 16.0,
3.0 / 16.0, 11.0 / 16.0, 1.0 / 16.0, 9.0 / 16.0,
15.0 / 16.0, 7.0 / 16.0, 13.0 / 16.0, 5.0 / 16.0
];
const x = Math.floor((u * 100.0) % 4.0);
const y = Math.floor((v * 100.0) % 4.0);
const threshold = bayer[x + y * 4];
return brightness > threshold ? 1.0 : 0.0;
}
hash(input) {
if (typeof input === 'number') {
const x = Math.sin(input) * 43758.5453;
return x - Math.floor(x);
}
else {
const p = {
x: (input.x * 123.34) % 1,
y: (input.y * 456.21) % 1
};
const dot = p.x * (p.x + 45.32) + p.y * (p.y + 45.32);
return ((p.x * p.y + dot) * 43758.5453) % 1;
}
}
noise(x, y) {
const p = { x, y };
const i = { x: Math.floor(p.x), y: Math.floor(p.y) };
const f = { x: p.x - i.x, y: p.y - i.y };
const u = {
x: f.x * f.x * (3.0 - 2.0 * f.x),
y: f.y * f.y * (3.0 - 2.0 * f.y)
};
const a = this.hash({ x: i.x, y: i.y });
const b = this.hash({ x: i.x + 1.0, y: i.y });
const c = this.hash({ x: i.x, y: i.y + 1.0 });
const d = this.hash({ x: i.x + 1.0, y: i.y + 1.0 });
return this.mix(this.mix(a, b, u.x), this.mix(c, d, u.x), u.y);
}
fbm(x, y) {
let value = 0.0;
let amplitude = 0.5;
let frequency = 3.0;
for (let i = 0; i < 5; i++) {
value += amplitude * this.noise(x * frequency, y * frequency);
amplitude *= 0.5;
frequency *= 2.0;
}
return value;
}
mix(a, b, t) {
return a * (1.0 - t) + b * t;
}
smoothstep(edge0, edge1, x) {
const t = Math.max(0, Math.min(1, (x - edge0) / (edge1 - edge0)));
return t * t * (3.0 - 2.0 * t);
}
async toPNG() {
const { PNG } = await Promise.resolve().then(() => __importStar(require('pngjs')));
const png = new PNG({ width: this.width, height: this.height });
for (let i = 0; i < this.pixels.length; i++) {
png.data[i] = this.pixels[i];
}
return PNG.sync.write(png);
}
getPixels() {
return this.pixels;
}
}
exports.WasmRasterizer = WasmRasterizer;
//# sourceMappingURL=wasm-rasterizer.js.map