Sprites.Media.Sprite.Draw

The Draw tool: the brush that lays colour on the canvas. Window is its own floating window, shown while the Draw tool is selected, with no close button since it must stay while Draw is current. The brush geometry turns a pointer into the box of cells the brush covers, and Cursor draws that box as a live outline over the sprite. The selector and the Tools window live in Sprites.Media.Sprite.Tool.

Sprites.Media.Sprite.Draw

Sprites.Media.Sprite.Draw constants Number, String

The brush cursor's line width and colour, in world units. One unit is one pixel of the sprite. Cursor draws its outline with this pair.

ConstantTypeValueDescription
Sprites.Media.Sprite.Draw.CursorWidthNumber0.12The cursor outline width, in world units.
Sprites.Media.Sprite.Draw.CursorColourString#ff3b30The cursor outline colour.
Sprites.Ui.Dom.Text('cursor ', Sprites.Media.Sprite.Draw.CursorWidth, ' ', Sprites.Media.Sprite.Draw.CursorColour);
The cursor outline width and colour.

Sprites.Media.Sprite.Draw.CursorColour String

The colour of the brush cursor outline. Cursor draws its live box over the sprite with this colour. It is a plain CSS colour string, a bright red.

Value #ff3b30.

Sprites.Ui.Dom.Tag('div', () => {
  Sprites.Ui.Dom.Style('background', Sprites.Media.Sprite.Draw.CursorColour);
  Sprites.Ui.Dom.Style('width', '48px');
  Sprites.Ui.Dom.Style('height', '48px');
  Sprites.Ui.Dom.Style('border-radius', '6px');
});
Sprites.Ui.Dom.Text(' CursorColour = ', Sprites.Media.Sprite.Draw.CursorColour);
The cursor outline colour, shown as a swatch.

Sprites.Media.Sprite.Draw.CursorWidth Number

The line width of the brush cursor outline, in world units. One unit is one pixel of the sprite. Cursor draws its box with this width, so the outline scales with the zoom.

Value 0.12.

Sprites.Ui.Dom.Text('CursorWidth = ', Sprites.Media.Sprite.Draw.CursorWidth, ' world units');
The cursor outline width, in world units.

Sprites.Media.Sprite.Draw.Window Void

Sprites.Media.Sprite.Draw.Window(visible, selectedDrawMode, radius, brushCss, paletteVisible)

The Draw tool's window: a floating panel with a Pencil and Eraser selector, the brush sizes and the current colour. It shows while visible is true, which the editor binds to the Draw tool being selected, and has no close button. Pencil lays the brush colour; Eraser clears cells to transparent. The colour square opens the Palette on a click.

InputTypeDescription
visibleSprites.Reactive.ValueShows the window while true.
selectedDrawModeSprites.Reactive.ValueThe pencil or eraser choice.
radiusSprites.Reactive.ValueThe brush reach the sizes select.
brushCssSprites.Reactive.ValueThe CSS colour shown in the square.
paletteVisibleSprites.Reactive.ValueSet true when the square is clicked.

Returns nothing.

const visible = Sprites.Reactive.Value(false);
const selectedDrawMode = Sprites.Reactive.Value('pencil');
const radius = Sprites.Reactive.Value(0);
const brushCss = Sprites.Reactive.Value('#ff8000');
const paletteVisible = Sprites.Reactive.Value(false);
Sprites.Ui.Button.SetValue(visible, true, 'Show Draw window');
Sprites.Media.Sprite.Draw.Window(visible, selectedDrawMode, radius, brushCss, paletteVisible);
Sprites.Ui.Dom.Text(' mode = ', selectedDrawMode, ', size = ', radius);
Show the Draw window; pick the pencil or eraser, a brush size, and the colour square.

Sprites.Media.Sprite.Draw.BrushBox Object

Sprites.Media.Sprite.Draw.BrushBox(col, row, radius)

The square a brush covers, centred on a pixel. radius 0 is one pixel, 1 is three by three, 2 is five by five. Returns the top left and the side.

InputTypeDescription
colNumberThe centre column.
rowNumberThe centre row.
radiusNumberThe brush reach.

Returns the { x, y, w, h } box, live going forward and a plain box inside a lens.

const box = Sprites.Media.Sprite.Draw.BrushBox(5, 5, 2);
const x = Sprites.Object.Field(box, 'x');
const y = Sprites.Object.Field(box, 'y');
const w = Sprites.Object.Field(box, 'w');
const h = Sprites.Object.Field(box, 'h');
Sprites.Ui.Dom.Text('x=', x, ' y=', y, ' w=', w, ' h=', h);
A radius two brush covers a five by five box.

The brush swatch colour Sprites.Reactive.Value

The Draw window shows the current brush colour in its swatch. The editor derives that swatch colour from the brush's packed colour with Sprites.Colour.Css, then passes it to Window as its brushCss input. The brush starts as Sprites.Media.Sprite.White, a packed colour.

Returns a read-only Sprites.Reactive.Value, the CSS colour.

const brush = Sprites.Reactive.Value(Sprites.Media.Sprite.White);
const css = Sprites.Colour.Css(brush);
Sprites.Ui.Dom.Text('brush css = ', css);
The brush's packed colour resolved to a CSS colour for the swatch.

Sprites.Media.Sprite.Draw.Cursor Void

Sprites.Media.Sprite.Draw.Cursor(active, over, at, radius, aspect)

The brush preview: a square outline around the pixels the brush would paint, drawn in sprite space inside a Vector. Shown while active and the pointer is over the sprite.

InputTypeDescription
activeSprites.Reactive.ValueShows the outline while true.
overSprites.Reactive.ValueTrue while the pointer is over the sprite.
atSprites.Reactive.ValueThe pointer in drawing units.
radiusSprites.Reactive.ValueThe brush reach.
aspectNumberThe pixel aspect ratio.

Returns nothing.

const at = Sprites.Reactive.Value({ x: 3.5, y: 3.5 });
const radius = Sprites.Reactive.Value(1);
const pan = Sprites.Reactive.Value({ x: 4, y: 4 });
const show = Sprites.Reactive.Value(10);
Sprites.Ui.Dom.Tag('div', () => {
  Sprites.Ui.Dom.Style('height', '160px');
  Sprites.Ui.Image.Vector(pan, show, () => {
    Sprites.Media.Sprite.Draw.Cursor(true, true, at, radius, 1);
  });
});
A three by three outline around the pointer's pixel.

Sprites.Media.Sprite.Draw.CursorBox Object

Sprites.Media.Sprite.Draw.CursorBox(at, aspect, radius)

The box of cells the brush covers, from the pointer. A composite: it reads the pointer's x and y, turns them into the centre column and row through Sprites.Maths, and hands those to BrushBox.

InputTypeDescription
atSprites.Reactive.ValueThe pointer in drawing units, a { x, y } value.
aspectNumber or Sprites.Reactive.ValueThe pixel aspect the x is divided by to find the column.
radiusNumber or Sprites.Reactive.ValueThe brush reach.

Returns the { x, y, w, h } box the brush covers.

const at = Sprites.Reactive.Value({ x: 6, y: 3 });
const box = Sprites.Media.Sprite.Draw.CursorBox(at, 2, 1);
const x = Sprites.Object.Field(box, 'x');
const y = Sprites.Object.Field(box, 'y');
const w = Sprites.Object.Field(box, 'w');
const h = Sprites.Object.Field(box, 'h');
Sprites.Ui.Dom.Text('x=', x, ' y=', y, ' w=', w, ' h=', h);
The pointer at x six over a two-wide pixel lands on column three, a radius one box.

Sprites.Media.Sprite.Draw.CursorH Sprites.Reactive.Value

Sprites.Media.Sprite.Draw.CursorH(box)

The height of the cursor box, in cells.

InputTypeDescription
boxSprites.Reactive.ValueA { x, y, w, h } cursor box, as from CursorBox or BrushBox.

Returns a read-only Sprites.Reactive.Value, the box height.

const box = Sprites.Media.Sprite.Draw.BrushBox(3, 3, 1);
const h = Sprites.Media.Sprite.Draw.CursorH(box);
Sprites.Ui.Dom.Text('CursorH = ', h);
A radius one box is three cells high.

Sprites.Media.Sprite.Draw.CursorW Sprites.Reactive.Value

Sprites.Media.Sprite.Draw.CursorW(box, aspect)

The drawn width of the cursor box: its cell width stretched by the aspect. A composite over Sprites.Maths.

InputTypeDescription
boxSprites.Reactive.ValueA { x, y, w, h } cursor box.
aspectNumber or Sprites.Reactive.ValueThe pixel aspect the width is stretched by.

Returns a read-only Sprites.Reactive.Value, the drawn width.

const box = Sprites.Media.Sprite.Draw.BrushBox(3, 3, 1);
const w = Sprites.Media.Sprite.Draw.CursorW(box, 2);
Sprites.Ui.Dom.Text('CursorW = ', w);
A three-cell box over a two-wide pixel draws six wide.

Sprites.Media.Sprite.Draw.CursorX Sprites.Reactive.Value

Sprites.Media.Sprite.Draw.CursorX(box, aspect)

The drawn left edge of the cursor box: its column stretched by the aspect. A composite over Sprites.Maths.

InputTypeDescription
boxSprites.Reactive.ValueA { x, y, w, h } cursor box.
aspectNumber or Sprites.Reactive.ValueThe pixel aspect the column is stretched by.

Returns a read-only Sprites.Reactive.Value, the drawn left edge.

const box = Sprites.Media.Sprite.Draw.BrushBox(3, 3, 1);
const x = Sprites.Media.Sprite.Draw.CursorX(box, 2);
Sprites.Ui.Dom.Text('CursorX = ', x);
The box's left column two over a two-wide pixel draws at four.

Sprites.Media.Sprite.Draw.CursorY Sprites.Reactive.Value

Sprites.Media.Sprite.Draw.CursorY(box)

The top edge of the cursor box, in cells.

InputTypeDescription
boxSprites.Reactive.ValueA { x, y, w, h } cursor box.

Returns a read-only Sprites.Reactive.Value, the box top edge.

const box = Sprites.Media.Sprite.Draw.BrushBox(3, 3, 1);
const y = Sprites.Media.Sprite.Draw.CursorY(box);
Sprites.Ui.Dom.Text('CursorY = ', y);
A radius one box around row three has its top at row two.