def get_cobweb_points(model, r, x, n):
    """
    Calculate the vertices of cobweb lines for a cobweb plot.

    Steps in the calculation:
    1) Let x = 0.5
    2) Start on the x-axis at the point (x, 0).
    3) Draw a vertical line to the red function curve: this point has the
    coordinates (x, f(x)).
    4) Draw a horizontal line from this point to the gray diagonal line: this
    point has the coordinates (f(x), f(x)).
    5) Draw a vertical line from this point to the red function curve: this
    point has the coordinates (f(x), f(f(x))).
    6) Repeat steps 4 and 5 recursively n times.

    Arguments
    ---------
    model: function
        defining an iterated map to simulate
    r: float
        growth rate parameter value to pass to the map
    x: float
        starting population value
    n: int
        number of iterations to run

    Returns
    -------
    tuple
        cobweb_x_vals, cobweb_y_vals
    """
    cobweb_points = [(x, 0)]
    for _ in range(n):
        y1 = model(x, r)
        cobweb_points.append((x, y1))
        cobweb_points.append((y1, y1))
        y2 = model(y1, r)
        cobweb_points.append((y1, y2))
        x = y1
    return zip(*cobweb_points)