vUX / CShapes / v4.1.0

Rings and borders, drawn on canvas.

One constructor, three shapes: a progress ring that animates between values, a marching-ants border, and a fixed dashed border. Sharp on every screen.

reduced motion: animation off
arc().draw(canvas, 87, "deployed")
animatedRectangle / radius 16

A colour that never sits still

config.lineColor is read on every frame, so a tween can write it while the dashes run.

animatedRectangle / counter-clockwise

Square corners, reversed

clockWise = false runs the dashes the other way round.

fixedRectangle

Drawn once, then left alone

A still dashed border for drop zones and placeholders.

const shapes = new CShapes(); shapes.arc(); shapes.animatedRectangle(); shapes.fixedRectangle();

01arc(): the progress ring

Every config property of arc() is wired below; any change redraws the ring. With a duration above 0, each draw animates from the value last shown on this canvas to the new one.

Config

Geometry

Colour and text

strokeColor
progressBackground
percentageFontColor
labelFontColor

Motion

canvas 260 x 260
idle

                
Equivalent code

                

Try stop() halfway through an animated draw, then draw() again: the next animation starts from the frozen frame. destroy() clears the canvas and resets the start value to 0.

02animatedRectangle(): marching ants

The dashes move a whole number of dash periods per cycle, so repeats loop without a jump. The canvas size and the config are re-read at the start of every cycle; lineColor is read on every frame.

Config
lineColor

Motion

canvas 100% x 220
the canvas covers this box;
the border runs round its edge
idle

                
Equivalent code

                

Square corners (radius 0) show half of lineWidth: the line runs on the canvas edge and the canvas clips its outer half. Rounded corners are drawn inset so they keep one even thickness. A lineWidth of 0 becomes 1.

03fixedRectangle(): drawn once

The same border without the motion: draw() strokes it once and returns. There is no stop() or destroy(); to remove it, clear the canvas yourself.

Config
lineColor
drop zone
Drop files here
(a still dashed border, redrawn on every change)
Equivalent code

                

04Many rings at once

A file-upload list: each row has its own arc() object and its own canvas, fed progress in uneven steps. Each step animates from where the last one ended, and callback marks the row done at 100.

05Bad input throws

Every setter and draw() checks its argument and throws at the call, so a typo fails in your code, not silently inside an animation frame. Each button below makes one bad call and prints what was thrown.

No error yet: press one of the buttons above.