What is SWRoundedTrapezoid?
SWRoundedTrapezoid extends SWTrapezoid by rounding each of
the four corners using quadratic Bézier curves. The shape is otherwise identical to its parent —
it supports the same parallel bases, height, regular/isosceles mode, breathing, rotation, grid
drawing, and dragging. The only new property is cornerRadius.
Inheritance
SWRoundedTrapezoid extends SWTrapezoid
Because the relationship is "is a" (a rounded trapezoid IS a trapezoid), all parent
capabilities are inherited for free. Only _drawAtPx(), reset(), and
toString() are overridden.
Key Formulas
Area = (a + b) / 2 × h
Left leg = √((b/2 − a/2 + offset)² + h²)
Right leg = √((b/2 − a/2 − offset)² + h²)
Perimeter = a + b + left leg + right leg
(note: perimeter does not include the arc adjustments at corners)
Constructor
new SWRoundedTrapezoid(cx, cy, topBase, bottomBase, height, fillColor, options)
| Option | Type | Default | Description |
cornerRadius | number | 10 | Corner rounding radius in pixels; clamped ≥ 0 |
strokeColor | SWColor | null | null | Outline colour; null = no stroke |
strokeWeight | number | 2 | Stroke width in pixels |
regular | boolean | true | Isosceles; forces offset = 0 |
offset | number | 0 | Horizontal shift of top base (px); only when regular = false |
Using the Controls
- Top Base / Bottom Base / Height / Corner Radius: Sliders above the accordion.
Corner Radius is expressed as a percentage of canvas width.
- Regular checkbox: Uncheck to reveal the Offset slider.
- Breathing, Spinning, Appearance, Actions: Same as SWTrapezoid demo.
- Drag: Click and drag the shape to reposition it.
Keyboard Shortcuts
- B — toggle breathing
- S — toggle spin
- R — factory reset
- Q — quit all animations