liveBook · Manning

Weighted average

As explained in Math for Web Design

A weighted average is an average in which each value contributes according to an assigned numerical weight.

A weighted average combines values while allowing some contributors to matter more than others. In frontend work, the weights can represent human visual sensitivity, opacity, or a changing position along an animation path. section 7.2.1 section 7.6.2

Listing 7.3 Converting RGB to grayscale using a weighted average
function rgbToGrayscale(r, g, b) {
    return 0.299 * r + 0.587 * g + 0.114 * b;    #1
}

This function converts an RGB color to a grayscale brightness value by weighting green more heavily than red and blue. section 7.2.1

The same idea appears in several visual calculations:

  • Grayscale conversion uses 0.299R + 0.587G + 0.114B, reflecting greater sensitivity to green and lower sensitivity to blue. The result ranges from black at 0 to white at 255. section 7.2.1
  • Alpha compositing blends a foreground and backdrop per channel: C_out = C_sα_s + C_bα_b(1 − α_s). With an opaque backdrop, the remaining background weight is 1 − α_s. section 7.6.2
  • A quadratic Bézier curve weights its start, control, and end points according to t: B(t) = (1 − t)²P₀ + 2(1 − t)tP₁ + t²P₂. section 11.1.2

A semitransparent color

Place rgb(0 0 255 / 0.5) over rgb(255 0 0). Each color contributes half its channel value, producing normalized RGB (0.5, 0, 0.5), or rgb(128 0 128). section 7.6.2

The practical question is not simply whether values are averaged, but what determines their influence. Choosing the weights exposes why a grayscale image reflects perceived brightness, why transparency reveals the backdrop, and why Bézier motion bends toward control points. section 7.2.1 section 11.1.2

How Math for Web Design covers it

How deep it goes
Explains coefficients and formulas through color and animation examples, without developing weighted-average theory beyond these applications.
Examples
Demonstrates RGB grayscale coefficients, a half-transparent blue square over red, and quadratic Bézier control-point weighting.
What you can do after
Apply weighted calculations to build grayscale colors, understand transparency results, and interpret Bézier animation paths.
How it connects
Connects weighted averages with grayscale conversion, alpha compositing, Bézier curves, opacity, and perceived brightness.

Also explained in

Compare how 5 books explain weighted average →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math for Web Design. The section links point to the parts of the book it draws on.