跳转到内容
查看源码

vector自动生成

分类:包 · 清单:use "kernels/";

矢量图形逐像素填充:从 SVG 导入的形状、填充规则、颜料与渐变。

Drawings filled pixel by pixel: the shapes entelechy import reads from SVG, their fill rules, paints and gradients, drawn whole or tiled.

Layer: Graphics. Uses: parallel.

use "vector.entpkg";
  • kernels/fill.ent — Drawing as Kernels. Kernels: vector.frame@1, vector.whole@1, vector.draw@1.
  • kernels/shape.ent — A drawing’s shapes as entelechy import writes them from an SVG.
  • kernels/tile.ent — The tiled form. Kernels: vector.reach@1, vector.shape_chunks@1, vector.tile_counts@1, vector.tile_fill@1, vector.placed@1, vector.segment_chunks@1, vector.units@1, vector.kept@1, vector.keep@1, vector.zeros@1, vector.backdrop@1, vector.draw_tiled@1.
  • graphs/draw.esn — A drawing through look at the window’s size, tiled.
  • graphs/drawing.esn — A drawing, whole and fitted to the window, over background.

tests/ holds scenes and their replays, run on every backend: many.replay, tiled.replay. Every Kernel of the package is reached by one of them.

Used by the vector example.

Kernel 执行模式 简述
vector.backdrop@1 scatter into input 12 with sum Each cell’s backdrop, a row of its tile to an element. Each of a unit’s segments wholly past the tile adds its turn to the rows it may cross, a pixel over its ends, each crossing tested at the row’s point in the drawing, read from the frame the drawing reads, as crossed tests it.
vector.draw@1 map The drawing over background, through frame, at the node’s domain: every pixel asks every shape and segment.
vector.draw_tiled@1 map The drawing, each pixel asking only its tile’s shapes and, of each, the cell’s own segments over its row’s backdrop: the same words vector.draw@1 draws.
vector.frame@1 map Where the look puts each pixel’s center in the drawing, and a pixel’s size there: the x of each of across’s columns, then the y of each of down’s rows, then the size; domain = count(across) + count(down) + 1. Every Kernel that asks where a pixel is reads it here, so they agree to the bit wherever each runs.
vector.keep@1 scatter into input 11 with max Each unit’s segments, in their order, into its part of the cells’ list: the walk vector.kept@1 counts.
vector.kept@1 map How many of its segments each unit gives its cell.
vector.placed@1 map Each segment on the canvas, as its shape’s box is.
vector.reach@1 map Each shape’s reach: the tiles its box, grown by two pixels, touches on the canvas.
vector.segment_chunks@1 map The box each chunk of segments spans on the canvas: least x and y, most x and y.
vector.shape_chunks@1 map What each chunk of shapes reaches together.
vector.tile_counts@1 map How many shapes reach each tile.
vector.tile_fill@1 scatter into input 5 with max Each tile’s shapes, in their order, into its part of the list: the walk vector.tile_counts@1 counts, stopped at its count.
vector.units@1 map How many units each cell is: its shape’s chunks.
vector.whole@1 map A look at the whole drawing: its middle, fitted to the picture.
vector.zeros@1 map A list of zeros, a row of each cell’s tile to each.
函数 简述
to_segment(p: Vec2, a: Vec2, b: Vec2) -> Float
spread_by(t: Float, spread: Int) -> Float
stops_at(stops: Rows<Stop>, first: Int, n: Int, t: Float) -> Vec4
paint_at(shape: Shape, stops: Rows<Stop>, p: Vec2) -> Vec4
crossed(w: Vec2, seg: Vec4, p: Vec2) -> Vec2
near(s: Shape, p: Vec2, pixel: Float) -> Bool
laid(below: Vec4, s: Shape, stops: Rows<Stop>, p: Vec2, pixel: Float, hit: Vec2) -> Vec4
seen(frame: Rows<Float>, wide: Int, pixel_at: Vec2) -> Vec3
fitted(size: Vec2, eye: Look, res: Vec2) -> Float
tile() -> Float
tile_columns(res: Vec2) -> Int
tile_rows(res: Vec2) -> Int
on_canvas(q: Vec2, view: Rows<Vec2>, look: Rows<Look>, res: Vec2) -> Vec2
reach_holds(r: Reach, tx: Int, ty: Int) -> Bool
chunk() -> Int
keeps(reach: Rows<Reach>, s: Int, tx: Int, ty: Int) -> Bool
in_rows(lo: Float, hi: Float, ty: Int) -> Bool
in_columns(lo: Float, hi: Float, tx: Int) -> Bool
past(lo: Float, tx: Int) -> Bool
own(on: Vec4, tx: Int, ty: Int) -> Bool
chunks_of(s: Shape) -> IVec2
part_of(s: Shape, c: Int) -> IVec2
work_unit_of(u: Int, units: Rows<Int>, unit_ends: Rows<Int>, tile_ends: Rows<Int>, tile_shapes: Rows<Int>, tiles: Grid<Int>, shapes: Rows<Shape>) -> Unit
名称 写法
Shape struct Shape
FillRule type FillRule = enum { NonZero, EvenOdd };
Paint type Paint = enum { Color, Linear, Radial };
Spread type Spread = enum { Pad, Reflect, Repeat };
Stop struct Stop { offset: Float; color: Vec4; }
Look struct Look { center: Vec2; zoom: Float; }
Reach struct Reach { x0: Int; y0: Int; x1: Int; y1: Int; }
Slot struct Slot { at: Int; value: Int; }
Unit struct Unit { cell: Int; tx: Int; ty: Int; chunk: Int; first: Int; count: Int; }
名称 接口 说明
draw input shapes: Rows<Shape>
input segments: Rows<Vec4>
input stops: Rows<Stop>
input view: Rows<Vec2>
input look: Rows<Look>
param background: Vec4 = vec4(1.0, 1.0, 1.0, 1.0)
output picture <- drawn.result
A drawing through look at the window’s size, tiled: the canvas is cut into tiles of 16 pixels, each keeps the shapes whose boxes reach it, each of those keeps the segments that reach the tile and the winding of those past it to the right, and each pixel asks only those. It draws the words vector.draw@1 draws, at the cost of a few passes over shapes and segments, so a large drawing (a map, a page of type) draws in time.
drawing input shapes: Rows<Shape>
input segments: Rows<Vec4>
input stops: Rows<Stop>
input view: Rows<Vec2>
param background: Vec4 = vec4(1.0, 1.0, 1.0, 1.0)
output picture <- drawn.picture
A drawing, whole and fitted to the window, over background. Its Fields are what entelechy import drawing.svg writes: node picture: graph “../../packages/vector.entpkg/graphs/drawing.esn” { shapes <- shapes; segments <- segments; stops <- stops; view <- view; }

Each cell’s backdrop, a row of its tile to an element. Each of a unit’s segments wholly past the tile adds its turn to the rows it may cross, a pixel over its ends, each crossing tested at the row’s point in the drawing, read from the frame the drawing reads, as crossed tests it.

执行模式 scatter into input 12 with sum
需要能力 field.read, field.write
输入 total: Rows<Int>, units: Rows<Int>, unit_ends: Rows<Int>, tile_ends: Rows<Int>, tile_shapes: Rows<Int>, tiles: Grid<Int>, shapes: Rows<Shape>, placed: Rows<Vec4>, chunks: Rows<Vec4>, segments: Rows<Vec4>, frame: Rows<Float>, canvas: Grid<Int>, zeros: Rows<Int>
参数 —
输出 result: Rows<Int>
源码 packages/vector.entpkg/kernels/tile.ent

The drawing over background, through frame, at the node’s domain: every pixel asks every shape and segment.

执行模式 map
需要能力 field.read, field.write
输入 shapes: Rows<Shape>, segments: Rows<Vec4>, stops: Rows<Stop>, frame: Rows<Float>
参数 background: Vec4 = [1.0, 1.0, 1.0, 1.0]
输出 result: Image
源码 packages/vector.entpkg/kernels/fill.ent

The drawing, each pixel asking only its tile’s shapes and, of each, the cell’s own segments over its row’s backdrop: the same words vector.draw@1 draws.

执行模式 map
需要能力 field.read, field.write
输入 shapes: Rows<Shape>, segments: Rows<Vec4>, stops: Rows<Stop>, frame: Rows<Float>, tile_counts: Rows<Int>, tile_ends: Rows<Int>, tile_shapes: Rows<Int>, units: Rows<Int>, unit_ends: Rows<Int>, kept: Rows<Int>, kept_ends: Rows<Int>, cell_segments: Rows<Int>, backdrop: Rows<Int>
参数 background: Vec4 = [1.0, 1.0, 1.0, 1.0]
输出 result: Image
源码 packages/vector.entpkg/kernels/tile.ent

Where the look puts each pixel’s center in the drawing, and a pixel’s size there: the x of each of across’s columns, then the y of each of down’s rows, then the size; domain = count(across) + count(down) + 1. Every Kernel that asks where a pixel is reads it here, so they agree to the bit wherever each runs.

执行模式 map
需要能力 field.read, field.write
输入 across: Grid<Int>, down: Grid<Int>, view: Rows<Vec2>, look: Rows<Look>
参数 —
输出 result: Rows<Float>
源码 packages/vector.entpkg/kernels/fill.ent

Each unit’s segments, in their order, into its part of the cells’ list: the walk vector.kept@1 counts.

执行模式 scatter into input 11 with max
需要能力 field.read, field.write
输入 total: Rows<Int>, kept: Rows<Int>, kept_ends: Rows<Int>, units: Rows<Int>, unit_ends: Rows<Int>, tile_ends: Rows<Int>, tile_shapes: Rows<Int>, tiles: Grid<Int>, shapes: Rows<Shape>, placed: Rows<Vec4>, chunks: Rows<Vec4>, slots: Rows<Int>
参数 —
输出 result: Rows<Int>
源码 packages/vector.entpkg/kernels/tile.ent

How many of its segments each unit gives its cell.

执行模式 map
需要能力 field.read, field.write
输入 total: Rows<Int>, units: Rows<Int>, unit_ends: Rows<Int>, tile_ends: Rows<Int>, tile_shapes: Rows<Int>, tiles: Grid<Int>, shapes: Rows<Shape>, placed: Rows<Vec4>, chunks: Rows<Vec4>
参数 —
输出 result: Rows<Int>
源码 packages/vector.entpkg/kernels/tile.ent

Each segment on the canvas, as its shape’s box is.

执行模式 map
需要能力 field.read, field.write
输入 segments: Rows<Vec4>, view: Rows<Vec2>, look: Rows<Look>, canvas: Grid<Int>
参数 —
输出 result: Rows<Vec4>
源码 packages/vector.entpkg/kernels/tile.ent

Each shape’s reach: the tiles its box, grown by two pixels, touches on the canvas.

执行模式 map
需要能力 field.read, field.write
输入 shapes: Rows<Shape>, view: Rows<Vec2>, look: Rows<Look>, canvas: Grid<Int>
参数 —
输出 result: Rows<Reach>
源码 packages/vector.entpkg/kernels/tile.ent

The box each chunk of segments spans on the canvas: least x and y, most x and y.

执行模式 map
需要能力 field.read, field.write
输入 placed: Rows<Vec4>
参数 —
输出 result: Rows<Vec4>
源码 packages/vector.entpkg/kernels/tile.ent

What each chunk of shapes reaches together.

执行模式 map
需要能力 field.read, field.write
输入 reach: Rows<Reach>
参数 —
输出 result: Rows<Reach>
源码 packages/vector.entpkg/kernels/tile.ent

How many shapes reach each tile.

执行模式 map
需要能力 field.read, field.write
输入 reach: Rows<Reach>, chunks: Rows<Reach>, tiles: Grid<Int>
参数 —
输出 result: Rows<Int>
源码 packages/vector.entpkg/kernels/tile.ent

Each tile’s shapes, in their order, into its part of the list: the walk vector.tile_counts@1 counts, stopped at its count.

执行模式 scatter into input 5 with max
需要能力 field.read, field.write
输入 reach: Rows<Reach>, chunks: Rows<Reach>, counts: Rows<Int>, ends: Rows<Int>, tiles: Grid<Int>, slots: Rows<Int>
参数 —
输出 result: Rows<Int>
源码 packages/vector.entpkg/kernels/tile.ent

How many units each cell is: its shape’s chunks.

执行模式 map
需要能力 field.read, field.write
输入 total: Rows<Int>, tile_shapes: Rows<Int>, shapes: Rows<Shape>
参数 —
输出 result: Rows<Int>
源码 packages/vector.entpkg/kernels/tile.ent

A look at the whole drawing: its middle, fitted to the picture.

执行模式 map
需要能力 field.read, field.write
输入 view: Rows<Vec2>
参数 —
输出 result: Rows<Look>
源码 packages/vector.entpkg/kernels/fill.ent

A list of zeros, a row of each cell’s tile to each.

执行模式 map
需要能力 field.read, field.write
输入 total: Rows<Int>
参数 —
输出 result: Rows<Int>
源码 packages/vector.entpkg/kernels/tile.ent

many.replay, tiled.replay