Problem 188113 · easy · Level 01 Prerequisites & Setup

Colour Steps Between Two Paints

vectors · element-wise operations · scaling · interpolation

A screen colour is a vector of three numbers [red, green, blue]. A designer wants a smooth band of n colours that starts exactly at the colour start, ends exactly at the colour end, and moves the same amount between every pair of neighbouring colours.

Write colour_steps(start, end, n) that returns a list of n colours (each a list of numbers) with these properties. The vectors can have any length, not only three, as long as start and end have the same length.

Examples

Input:  start = [255, 0, 0], end = [0, 0, 255], n = 3
Output: [[255.0, 0.0, 0.0], [127.5, 0.0, 127.5], [0.0, 0.0, 255.0]]
Explanation: the middle colour is halfway along the way from red to blue.

Input:  start = [0, 100], end = [30, 40], n = 4
Output: [[0.0, 100.0], [10.0, 80.0], [20.0, 60.0], [30.0, 40.0]]
Explanation: every step adds [10, -20], a third of the full change [30, -60].

Constraints

  • 2 <= n <= 1000
  • 1 <= len(start) == len(end) <= 50; values are ints or floats between -10**6 and 10**6
  • do not round; answers are compared with a tolerance of 1e-6, so ints and floats are both fine

Goals

  • Subtract, scale and add vectors position by position
  • See the points between two vectors as a straight path from one to the other
  • Space the steps evenly and include both ends
Starting Python…