Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(look): a picture's layers blurred, and noise as a fill

yhhdcf485b81631
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 433f7957f..784a4ae71 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,7 +22,7 @@ published separately; it ships inside the editor.
- **Glyphs can be put on the atlas before they are shown.** The first page of a novel is hundreds of new characters, all landing in one frame. `preloadGlyphs(app, label, text, { budgetMs })` makes them ahead of time, a slice a frame, drawn as that `Text` will draw them, and returns `progress`, `done` and `release()`. On a Snapdragon 8 Elite a book's 2992 characters at 28 px took 145 ms over 25 frames with the worst frame at 9.5 ms, after which the first page's frame went from 49 to 11 ms and no page made a new glyph. Preloaded glyphs hold their atlas pages (4 MB each, a few hundred characters at that size) until `release()`.
- **Voxel GI lights what the camera does not see, and bounces light more than once.** The cache now reads the sun's shadow map back into the world, so a surface the sun lights behind or beside the camera still sends light into the view. Each surface also gives off again the bounce light it received, so a corner or a floor in shade gets light that took two or more bounces to reach it. A ray now brings what it meets at full strength however far it went (it used to fade with distance, 40% at 4 m with 12 cm voxels). Each voxel is weighed by how much of it a surface covers, so a bright patch no longer lights like the whole voxel around it. Together these keep the result close to a path tracer's whatever the voxel size. In a sunlit test room the whole frame carries 0.95 of Cycles' light at the default size and 0.74 at 12 cm voxels; before, it was 0.54 at the default and darker the finer the grid. With the lit patch behind the camera, the walls went from no bounce light to 25–57%. A closed room the sun only lights from outside stays dark. Two inspector controls tune it: **Off-screen Sun Albedo** (the colour the shadow map cannot give, assumed) and **Multi-bounce**. A fine grid no longer drops every voxel: a count truncated by the cache's ageing had kept them below the two samples a ray asks for. The WebGL2 fallback does the same in its own passes: each voxel asks the sun's map whether a sunlit surface stands in it, and traces two rays through last frame's grid for the light it is given. In the test room it carries 1.00 of Cycles' light at the default size (it was 0.56) and 0.80 at 12 cm; with the lit patch behind the camera 0.20 (it was 0). Its voxel pass costs about 1.3 ms more at 720p on a desktop.
-- **An AI can draw 2D pictures.** `image_write` turns layers into a `.png` beside an `.esimage`: shapes and SVG paths, gradients, strokes, shadows and glows, clipping and cutting, or pixel art as rows of characters. It answers with the picture on a mid ground and a light check and at 96, 64, 48 and 32 pixels, to look at and correct; `image_edit` changes one layer, a row or a block of pixels without restating the rest, and moves layers or wraps them in a group. Strokes can keep sharp corners, and the reply measures where each layer ended up. `image_read` enlarges a part, and `image_set` shows several together with the stroke widths and size of each. Drawn on the CPU, so a source makes the same picture on any machine.
+- **An AI can draw 2D pictures.** `image_write` turns layers into a `.png` beside an `.esimage`: shapes and SVG paths, gradients, strokes, shadows and glows, clipping and cutting, or pixel art as rows of characters. It answers with the picture on a mid ground and a light check and at 96, 64, 48 and 32 pixels, to look at and correct; `image_edit` changes one layer, a row or a block of pixels without restating the rest, and moves layers or wraps them in a group. Strokes can keep sharp corners, and the reply measures where each layer ended up. A layer or group can be blurred, for depth of field, and a fill can be noise for cloud, texture and film grain, the same picture from the same seed. `image_read` enlarges a part, and `image_set` shows several together with the stroke widths and size of each. Drawn on the CPU, so a source makes the same picture on any machine.
- **An AI can build a person, and not a picture of one.** The `humanoid` step makes a whole body from a few numbers, with fingers, a face and ears, seen right from every side, and `rig: { humanoid: true }` gives it bones that fit. `garment` makes clothes from the body's own surface: loose or tight, a bell sleeve that hangs, a clean hem, a thickness; what a body wears now takes its weights from the skin under it, so an arm stays in its sleeve. `pose` holds a body in a pose by angles, or with `reach` by where a hand should be. `organic` gains `limb`, cross-sections along a path, and `fine`, regions split finer on one skin. `displace` gains `folds`, running the way cloth hangs. `scene_views` no longer takes on a shot's lens blur and grade.
diff --git a/desktop b/desktop
index aa1d00a21..6bee848c8 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit aa1d00a214af68ab5cf6311d0709583dd62c01ad
+Subproject commit 6bee848c8cb599abe7b2c84f39debf0e4012ac92
diff --git a/pipeline/src/image/imageRaster.ts b/pipeline/src/image/imageRaster.ts
index 6dc329a70..dd8f70066 100644
--- a/pipeline/src/image/imageRaster.ts
+++ b/pipeline/src/image/imageRaster.ts
@@ -416,6 +416,48 @@ function shifted(src: Float32Array, w: number, h: number, dx: number, dy: number
// ---- Paint ----------------------------------------------------------------------
/** A fill as a function of a pixel. Its coordinates go with its layer's, turned and all. */
+/** Written out, not computed by cos and sin, whose last bits are the engine's to choose. */
+const NOISE_DIRECTIONS: readonly (readonly [number, number])[] = [
+ [1, 0], [0.9239, 0.3827], [0.7071, 0.7071], [0.3827, 0.9239], [0, 1], [-0.3827, 0.9239], [-0.7071, 0.7071], [-0.9239, 0.3827],
+ [-1, 0], [-0.9239, -0.3827], [-0.7071, -0.7071], [-0.3827, -0.9239], [0, -1], [0.3827, -0.9239], [0.7071, -0.7071], [0.9239, -0.3827],
+];
+
+/** How much a corner of the lattice lifts the point @p dx, @p dy away. Integer hashing, so it is the same on every machine. */
+function cornerLift(ix: number, iy: number, seed: number, dx: number, dy: number): number {
+ let h = Math.imul(ix, 374761393) + Math.imul(iy, 668265263) + Math.imul(seed, 1442968193);
+ h = Math.imul(h ^ (h >>> 13), 1274126177);
+ h = Math.imul(h ^ (h >>> 16), 2246822519);
+ const d = NOISE_DIRECTIONS[((h ^ (h >>> 16)) >>> 0) % NOISE_DIRECTIONS.length]!;
+ return d[0] * dx + d[1] * dy;
+}
+
+const fade = (t: number): number => t * t * t * (t * (t * 6 - 15) + 10);
+
+/** Gradient noise, about -0.7..0.7: a value on a lattice alone shows the lattice, as boxes in a large soft cloud. */
+function gradientNoise(x: number, y: number, seed: number): number {
+ const [ix, iy] = [Math.floor(x), Math.floor(y)];
+ const [fx, fy] = [x - ix, y - iy];
+ const [sx, sy] = [fade(fx), fade(fy)];
+ const top = cornerLift(ix, iy, seed, fx, fy) * (1 - sx) + cornerLift(ix + 1, iy, seed, fx - 1, fy) * sx;
+ const bottom = cornerLift(ix, iy + 1, seed, fx, fy - 1) * (1 - sx) + cornerLift(ix + 1, iy + 1, seed, fx - 1, fy - 1) * sx;
+ return top * (1 - sy) + bottom * sy;
+}
+
+/** Spread out to 0..1, so that the stops at the ends are reached. */
+const NOISE_CONTRAST = [1.15, 1.3, 1.4, 1.45, 1.45, 1.45, 1.45, 1.45];
+
+function fractalNoise(x: number, y: number, octaves: number, seed: number): number {
+ let [sum, weight, amplitude, frequency] = [0, 0, 1, 1];
+ for (let i = 0; i < octaves; i++) {
+ // Off the lattice, where this noise is always nothing.
+ sum += gradientNoise(x * frequency + 0.37, y * frequency + 0.61, seed + i * 101) * amplitude;
+ weight += amplitude;
+ amplitude *= 0.5;
+ frequency *= 2;
+ }
+ return Math.max(0, Math.min(1, 0.5 + (sum / weight) * NOISE_CONTRAST[octaves - 1]!));
+}
+
function paintOf(fill: ImageFill, m: Matrix): (x: number, y: number) => Rgba {
if (typeof fill === 'string') {
const c = parseColor(fill);
@@ -434,6 +476,13 @@ function paintOf(fill: ImageFill, m: Matrix): (x: number, y: number) => Rgba {
}
return stops[stops.length - 1]![1];
};
+ if (fill.type === 'noise') {
+ const [scale, octaves, seed] = [fill.scale ?? 32, fill.octaves ?? 4, fill.seed ?? 0];
+ return (x, y) => {
+ const p = apply(inverse, [x - 0.5, y - 0.5]);
+ return at(fractalNoise(p[0] / scale, p[1] / scale, octaves, seed));
+ };
+ }
if (fill.type === 'linear') {
const [a, b] = [fill.from, fill.to];
const [ex, ey] = [b[0] - a[0], b[1] - a[1]];
@@ -550,6 +599,25 @@ function drawLayer(c: Canvas, layer: ImageLayer, parent: Matrix, drawn: Drawn):
const clip = layer.clip ? drawn.masks.get(layer.clip) : undefined;
if (layer.clip && !clip) drawn.notes.push(`layer ${layer.id ?? layer.shape}: clip "${layer.clip}" names no layer drawn before it`);
+ if (layer.blur) {
+ const { blur, opacity: _o, blend: _b, clip: _c, ...sharp } = layer;
+ const inner = new Canvas(w, h);
+ drawLayer(inner, sharp, parent, drawn);
+ // Blurred as stored, colour already times alpha: blurring straight colour would bring the black of empty pixels in round the edge.
+ const [r, g, b, a] = [0, 1, 2, 3].map((k) => {
+ const channel = new Float32Array(w * h);
+ for (let i = 0; i < channel.length; i++) channel[i] = inner.px[i * 4 + k]!;
+ return blurMask(channel, w, h, blur * drawnScale(parent));
+ }) as [Float32Array, Float32Array, Float32Array, Float32Array];
+ if (layer.id) drawn.masks.set(layer.id, a);
+ for (let i = 0; i < a.length; i++) {
+ const alpha = a[i]!;
+ if (alpha <= 0) continue;
+ put(c, i, r[i]! / alpha, g[i]! / alpha, b[i]! / alpha, alpha * opacity * (clip ? clip[i]! : 1), blend);
+ }
+ return;
+ }
+
if (layer.shape === 'group') {
const inner = new Canvas(w, h);
const m = times(parent, transformOf(layer.transform, [w / 2, h / 2]));
diff --git a/pipeline/src/image/imageSource.ts b/pipeline/src/image/imageSource.ts
index 01d00b5df..980ff9326 100644
--- a/pipeline/src/image/imageSource.ts
+++ b/pipeline/src/image/imageSource.ts
@@ -11,7 +11,9 @@ export const MAX_IMAGE_SIZE = 2048;
export type ImageFill = string
| { type: 'linear'; from: readonly [number, number]; to: readonly [number, number]; stops: readonly (readonly [number, string])[] }
- | { type: 'radial'; at: readonly [number, number]; radius: number; stops: readonly (readonly [number, string])[] };
+ | { type: 'radial'; at: readonly [number, number]; radius: number; stops: readonly (readonly [number, string])[] }
+ /** The same picture on every machine: it comes from `seed` and never from a random number. */
+ | { type: 'noise'; scale?: number; octaves?: number; seed?: number; stops: readonly (readonly [number, string])[] };
export interface ImageEffect {
type: 'shadow' | 'glow' | 'innerShadow' | 'innerGlow';
@@ -60,6 +62,8 @@ export interface ImageLayer {
clip?: string;
erase?: boolean;
visible?: boolean;
+ /** Softens the layer as drawn, with its effects, in the picture's pixels. On a group it softens the group as one thing. */
+ blur?: number;
}
export interface ImageSource {
@@ -77,7 +81,12 @@ function checkFill(v: unknown): string | null {
if (typeof v === 'string') return isColor(v) ? null : `${JSON.stringify(v)} must be #rgb, #rgba, #rrggbb or #rrggbbaa`;
const f = v as Record<string, unknown> | null;
if (typeof f !== 'object' || f === null) return 'must be a colour or a gradient';
- if (f.type !== 'linear' && f.type !== 'radial') return 'a gradient has type linear or radial';
+ if (f.type !== 'linear' && f.type !== 'radial' && f.type !== 'noise') return 'a gradient has type linear, radial or noise';
+ if (f.type === 'noise') {
+ if (f.scale !== undefined && !(isNum(f.scale) && (f.scale as number) > 0)) return 'noise scale must be a positive number of pixels';
+ if (f.octaves !== undefined && !(Number.isInteger(f.octaves) && (f.octaves as number) >= 1 && (f.octaves as number) <= 8)) return 'noise octaves must be a whole number from 1 to 8';
+ if (f.seed !== undefined && !Number.isInteger(f.seed)) return 'noise seed must be a whole number';
+ }
if (f.type === 'linear' && !(isPair(f.from) && isPair(f.to))) return 'a linear gradient needs from and to, each [x, y]';
if (f.type === 'radial' && !(isPair(f.at) && isNum(f.radius) && (f.radius as number) > 0)) return 'a radial gradient needs at: [x, y] and a positive radius';
if (!Array.isArray(f.stops) || f.stops.length < 2) return 'a gradient needs two stops or more, each [0..1, colour]';
@@ -87,7 +96,7 @@ function checkFill(v: unknown): string | null {
return null;
}
-const FIELDS = ['id', 'shape', 'at', 'size', 'radius', 'radii', 'inner', 'count', 'tooth', 'turn', 'points', 'd', 'rows', 'palette', 'scale', 'layers', 'fill', 'stroke', 'opacity', 'blend', 'transform', 'mirror', 'effects', 'clip', 'erase', 'visible'];
+const FIELDS = ['id', 'shape', 'at', 'size', 'radius', 'radii', 'inner', 'count', 'tooth', 'turn', 'points', 'd', 'rows', 'palette', 'scale', 'layers', 'fill', 'stroke', 'opacity', 'blend', 'transform', 'mirror', 'effects', 'clip', 'erase', 'visible', 'blur'];
const SHAPES: readonly ImageShape[] = ['rect', 'circle', 'ellipse', 'ring', 'polygon', 'line', 'star', 'gear', 'path', 'pixels', 'group'];
function checkLayer(l: Record<string, unknown>, where: string, ids: Set<string>): void {
@@ -157,6 +166,8 @@ function checkLayer(l: Record<string, unknown>, where: string, ids: Set<string>)
if (s.cap !== undefined && !['round', 'butt', 'square'].includes(s.cap as string)) fail('stroke cap must be round, butt or square');
}
if (!['group', 'pixels', 'line'].includes(l.shape as string) && l.fill === undefined && l.stroke === undefined && !l.erase) fail('it needs a fill or a stroke, or it draws nothing');
+ if (l.blur !== undefined && !(isNum(l.blur) && (l.blur as number) >= 0)) fail('blur must be 0 or more, in pixels');
+ if (l.blur && l.erase) fail('blur does not go with erase; put what cuts in a group with what it cuts, and blur the group');
if (l.opacity !== undefined && !(isNum(l.opacity) && l.opacity >= 0 && l.opacity <= 1)) fail('opacity must be 0..1');
if (l.blend !== undefined && !['normal', 'multiply', 'screen', 'overlay', 'add'].includes(l.blend as string)) fail('blend must be normal, multiply, screen, overlay or add');
if (l.mirror !== undefined && l.mirror !== 'x' && l.mirror !== 'y') fail('mirror must be x or y');
diff --git a/pipeline/tests/image-raster.test.ts b/pipeline/tests/image-raster.test.ts
index c84ab8949..d625678b0 100644
--- a/pipeline/tests/image-raster.test.ts
+++ b/pipeline/tests/image-raster.test.ts
@@ -471,6 +471,147 @@ describe('the sheet to look at', () => {
});
});
+describe('blur', () => {
+ const dot: ImageLayer = { shape: 'rect', at: [24, 24], size: [16, 16], fill: RED };
+
+ it('softens an edge and keeps how much there is', () => {
+ const [sharp, soft] = [draw([dot]), draw([{ ...dot, blur: 4 }])];
+ expect(px(sharp, 18, 32)[3]).toBe(0);
+ expect(px(soft, 18, 32)[3]).toBeGreaterThan(5);
+ expect(px(soft, 32, 32)[3]).toBeLessThan(255);
+ const total = (img: ReturnType<typeof draw>): number => { let s = 0; for (let i = 3; i < img.rgba.length; i += 4) s += img.rgba[i]!; return s; };
+ expect(Math.abs(total(sharp) - total(soft)) / total(sharp)).toBeLessThan(0.02);
+ });
+
+ it('does not bring black in round the edge', () => {
+ const soft = draw([{ ...dot, blur: 4 }]);
+ for (let x = 14; x < 24; x++) if (px(soft, x, 32)[3]! > 2) expect(px(soft, x, 32)[0]).toBeGreaterThan(245);
+ });
+
+ it('stays solid to the edge of the picture when the layer fills it', () => {
+ expect(px(draw([{ shape: 'rect', at: [0, 0], size: [64, 64], fill: RED, blur: 6 }]), 0, 0)).toEqual([255, 0, 0, 255]);
+ });
+
+ it('softens a group as one thing, with its effects, and leaves what is outside it sharp', () => {
+ const img = draw([
+ { shape: 'group', blur: 3, opacity: 0.5, layers: [dot, { shape: 'rect', at: [40, 24], size: [8, 16], fill: BLUE }] },
+ { shape: 'rect', at: [0, 0], size: [4, 4], fill: BLUE },
+ ]);
+ expect(px(img, 2, 2)).toEqual([0, 0, 255, 255]);
+ expect(px(img, 4, 2)[3]).toBe(0);
+ // Where the two meet the colours mix, and nothing is over half there.
+ expect(px(img, 40, 32)[0]).toBeGreaterThan(40);
+ expect(px(img, 40, 32)[2]).toBeGreaterThan(40);
+ expect(px(img, 32, 32)[3]).toBeLessThanOrEqual(128);
+ const shadowed = draw([{ ...dot, blur: 2, effects: [{ type: 'shadow', x: 10, blur: 0, opacity: 1 }] }]);
+ expect(px(shadowed, 45, 32)[3]).toBeGreaterThan(200);
+ });
+
+ it('scales with the group it is in, keeps its clip and its blend', () => {
+ const at = (scale: number): number => px(draw([{ shape: 'group', transform: { scale, origin: [32, 32] }, layers: [{ shape: 'rect', at: [24, 24], size: [16, 16], fill: RED, blur: 2 }] }]), 32 - Math.round(8 * scale) - 2 * scale, 32)[3]!;
+ expect(Math.abs(at(1) - at(2))).toBeLessThan(40);
+ const clipped = draw([{ id: 'c', shape: 'rect', at: [0, 0], size: [32, 64], fill: BLUE }, { ...dot, blur: 4, clip: 'c' }]);
+ expect(px(clipped, 40, 32)[0]).toBe(0);
+ const screened = draw([{ shape: 'rect', at: [0, 0], size: [64, 64], fill: '#808080' }, { shape: 'rect', at: [0, 0], size: [64, 64], fill: '#808080', blur: 2, blend: 'screen' }]);
+ expect(px(screened, 32, 32)[0]).toBeGreaterThan(180);
+ });
+
+ it('lets a shape clip softly to it', () => {
+ const img = draw([{ id: 's', shape: 'rect', at: [24, 24], size: [16, 16], fill: '#ffffff', blur: 4, opacity: 0 }, { shape: 'rect', at: [0, 0], size: [64, 64], fill: RED, clip: 's' }]);
+ expect(px(img, 32, 32)[3]).toBeGreaterThan(px(img, 22, 32)[3]!);
+ expect(px(img, 22, 32)[3]).toBeGreaterThan(0);
+ });
+
+ it('refuses what it cannot do', () => {
+ const bad = (fields: object): unknown => validateImageSource({ size: 8, layers: [{ shape: 'circle', at: [4, 4], radius: 2, fill: RED, ...fields }] });
+ expect(() => bad({ blur: -1 })).toThrow(/blur must be 0 or more/);
+ expect(() => bad({ blur: 2, erase: true })).toThrow(/does not go with erase/);
+ });
+});
+
+describe('noise', () => {
+ const grey = (fields: object = {}): ImageLayer => ({ shape: 'rect', at: [0, 0], size: [64, 64], fill: { type: 'noise', stops: [[0, '#000000'], [1, '#ffffff']], ...fields } as never });
+ const reds = (img: ReturnType<typeof draw>): number[] => Array.from({ length: 64 * 64 }, (_, i) => img.rgba[i * 4]!);
+
+ it('is the same from the same seed, and differs from another', () => {
+ expect(draw([grey({ seed: 5 })]).rgba).toEqual(draw([grey({ seed: 5 })]).rgba);
+ expect(draw([grey({ seed: 5 })]).rgba).not.toEqual(draw([grey({ seed: 6 })]).rgba);
+ });
+
+ it('holds a value pinned here, so the picture cannot change between machines or versions unnoticed', () => {
+ const img = draw([grey({ seed: 1 })]);
+ let sum = 0;
+ for (const v of reds(img)) sum = (Math.imul(sum, 31) + v) | 0;
+ expect(sum).toBe(NOISE_PIN);
+ });
+
+ it('spends the whole range of its stops, about the middle', () => {
+ for (const octaves of [1, 2, 4, 8]) {
+ const v = reds(draw([grey({ octaves, scale: 8 })]));
+ const mean = v.reduce((a, b) => a + b, 0) / v.length;
+ expect(mean).toBeGreaterThan(90);
+ expect(mean).toBeLessThan(165);
+ expect(Math.max(...v) - Math.min(...v)).toBeGreaterThan(150);
+ }
+ });
+
+ it('shows no boxes of its lattice in a large soft cloud', () => {
+ // Along the lattice's own axis and across it the change is alike; value noise changes less along an axis.
+ const img = draw([{ shape: 'rect', at: [0, 0], size: [256, 256], fill: { type: 'noise', scale: 40, octaves: 1, stops: [[0, '#000000'], [1, '#ffffff']] } }], [256, 256]);
+ const change = (dx: number, dy: number): number => {
+ let t = 0;
+ for (let y = 8; y < 240; y++) for (let x = 8; x < 240; x++) t += Math.abs(px(img, x, y)[0]! - px(img, x + dx, y + dy)[0]!);
+ return t;
+ };
+ const [along, diagonal] = [change(4, 0), change(3, 3)];
+ expect(Math.abs(along - diagonal) / along).toBeLessThan(0.1);
+ });
+
+ it('has blobs of the size it is told', () => {
+ const stepAlong = (scale: number): number => {
+ const img = draw([grey({ scale, octaves: 1 })]);
+ let total = 0;
+ for (let x = 0; x < 63; x++) total += Math.abs(px(img, x, 20)[0]! - px(img, x + 1, 20)[0]!);
+ return total;
+ };
+ expect(stepAlong(4)).toBeGreaterThan(stepAlong(32) * 3);
+ });
+
+ it('gives a different value to each pixel at size 1, for grain', () => {
+ const img = draw([grey({ scale: 1, octaves: 1 })]);
+ let moved = 0;
+ for (let x = 0; x < 63; x++) if (Math.abs(px(img, x, 20)[0]! - px(img, x + 1, 20)[0]!) > 10) moved++;
+ expect(moved).toBeGreaterThan(40);
+ });
+
+ it('fades through clear stops, and is cut by the shape', () => {
+ const img = draw([{ shape: 'circle', at: [32, 32], radius: 16, fill: { type: 'noise', scale: 8, stops: [[0, '#ffffff00'], [1, '#ffffffff']] } }]);
+ const alphas = new Set<number>();
+ for (let x = 20; x < 44; x++) alphas.add(px(img, x, 32)[3]!);
+ expect(alphas.size).toBeGreaterThan(5);
+ expect(px(img, 2, 2)[3]).toBe(0);
+ });
+
+ it('stretches with the transform', () => {
+ const img = draw([{ shape: 'rect', at: [-200, -200], size: [500, 500], transform: { scale: [8, 1], origin: [0, 0] }, fill: { type: 'noise', scale: 4, octaves: 1, stops: [[0, '#000000'], [1, '#ffffff']] } }]);
+ const change = (dx: number, dy: number): number => {
+ let t = 0;
+ for (let i = 0; i < 50; i++) t += Math.abs(px(img, 5 + i * dx, 5 + i * dy)[0]! - px(img, 5 + (i + 1) * dx, 5 + (i + 1) * dy)[0]!);
+ return t;
+ };
+ expect(change(0, 1)).toBeGreaterThan(change(1, 0) * 3);
+ });
+
+ it('works for a stroke, and refuses what is not one', () => {
+ expect(px(draw([{ shape: 'line', points: [[0, 32], [64, 32]], stroke: { color: { type: 'noise', scale: 8, stops: [[0, '#ff0000'], [1, '#ff0000']] } as never, width: 4 } }]), 32, 32)).toEqual([255, 0, 0, 255]);
+ const bad = (fill: object): unknown => validateImageSource({ size: 8, layers: [{ shape: 'rect', at: [0, 0], size: [8, 8], fill: { type: 'noise', stops: [[0, '#000'], [1, '#fff']], ...fill } }] });
+ expect(() => bad({ scale: 0 })).toThrow(/scale must be a positive/);
+ expect(() => bad({ octaves: 9 })).toThrow(/octaves must be/);
+ expect(() => bad({ seed: 1.5 })).toThrow(/seed must be/);
+ expect(() => validateImageSource({ size: 8, layers: [{ shape: 'rect', at: [0, 0], size: [8, 8], fill: { type: 'wavy', stops: [] } }] })).toThrow(/linear, radial or noise/);
+ });
+});
+
describe('what it measures', () => {
it('finds where the picture is solid and how much of it that is', () => {
const img = draw([{ shape: 'rect', at: [10, 20], size: [16, 8], fill: RED }]);
@@ -532,6 +673,8 @@ describe('a set and a close look', () => {
});
});
+const NOISE_PIN = -1320521626;
+
describe('the source', () => {
const ok = (layers: unknown[]): unknown => ({ size: 16, layers });
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 7ad361384..82a9d2912 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -3888,6 +3888,10 @@ export const NOTED = {
{"note":"An AI can draw 2D pictures."},
"feat(look): layers moved and wrapped, one pixel changed, a set and a close look drawn":
{"note":"An AI can draw 2D pictures."},
+ "feat(look): a picture's layers blurred, and noise as a fill":
+ {"note":"An AI can draw 2D pictures."},
+ "feat(mcp): image_write documents blur and noise":
+ {"note":"An AI can draw 2D pictures."},
"feat(look): stroke joins and ends, what a picture measures, pixels by the block":
{"note":"An AI can draw 2D pictures."},
"feat(mcp): a picture's reply measures it; stroke join and cap, pixel blocks":