On this page
Server-side ports of the browser's computed gradient, noise, dither, and pattern-stamp drawing tools, reproducing each algorithm deterministically byte-for-byte.
#server.src.pixelweaver.ws_drawing
#server.src.pixelweaver.ws_drawing
Faithful server-side mirror of the browser's computed drawing tools.
The gradient, noise, dither, and pattern-stamp tools do NOT dispatch per-pixel draw_pixels -- each dispatches a bespoke command (draw_gradient, draw_noise, draw_dither, draw_pattern) carrying its algorithm parameters, and computes the affected pixels locally in the browser. Before this module the server did not cover those command types, so those edits were thrown away (blank canvas on reload / blank exports -- defect (a)).
Each function here reproduces the corresponding client algorithm from plugins/builtin/*-tool.ts byte-for-byte, so the authoritative buffer the server writes is identical to what the user sees locally. Determinism is non-negotiable: the noise tool's randomness comes from a seed carried on the command (params.seed, resolved to a concrete value at dispatch time), fed through a faithful port of the client's Mulberry32 PRNG -- the server never rolls its own randomness.
Returned pixels are (x, y, r, g, b, a) tuples applied with plain overwrite semantics (matching the client PixelBuffer.setPixel and the server _Buffer.set_pixel).
#_js_round
def _js_round(x: float) -> intJS Math.round: floor(x + 0.5) (half rounds toward +Infinity).
Python's built-in round uses banker's rounding, which diverges on .5 values; colour channels are non-negative so this port is exact.
#mulberry32
def mulberry32(seed: int)Return a callable producing floats in [0, 1), matching the client PRNG.
#gradient_pixels
def gradient_pixels(width: int, height: int, x0: int, y0: int, x1: int, y1: int, color0: str, color1: str, mode: str) -> list[Pixel]Mirror computeGradient (gradient-tool.ts). Fills the full canvas.
#dither_pixels
def dither_pixels(x: int, y: int, w: int, h: int, color0: str, color1: str, matrix_size: int) -> list[Pixel]Mirror computeDither (dither-tool.ts).
#noise_pixels
def noise_pixels(x: int, y: int, w: int, h: int, colors: list[str], density: float, seed: int) -> list[Pixel]Mirror computeNoise (noise-tool.ts) with the seeded PRNG.
#pattern_pixels
def pattern_pixels(points: Iterable[dict[str, Any]], pattern_width: int, pattern_height: int, pattern_data: list[int]) -> list[Pixel]Mirror computePatternPixels (pattern-stamp-tool.ts).