Purpose of the sketch: Create an array of points whose y-positions are calculated from Perlin noise. As I increase the slider I should increase the number of points and Perlin noise domain i.e. larger values should have more undulations.

Here's how I calculate the space between the points:

horizontal_space = numberPoints x pointWidth + ( numberPoints-1) x spacerWidth

spacerWidth = (horizontal_space - (numberPoints x pointWidth)) / (numberPoints-1)

Problem: 1. As I increase the number of points the space between the final point and the edge of the window increases. 2. Moving the slider creates unexpected results which are rectified when the slider is pulsed - I think this is caused by mismatched events between calculating the inter-point space length and building the list.

I'm spending too much time trying to fix it and could use your assistance in getting the desired result.