The slope of $nx\ \%\ m$ (This is a follow-up question to another question I asked at MSE. I edited due to an important hint from Will Sawin - see his comments below.)

There will be this question at the end of this post:

  
*
  
*Prove that the slope of $nx\ \%\ m$ (as defined below) equals $n$ for all $n,m$.
  

But let's start gently.

Let $x\ \%\ m$ be the residue of $x$ modulo $m$, i.e.
$$x \equiv x\ \%\ m\pmod{m}$$
Let $\mu^n_m$ denote "multiplication by $n$ modulo $m$", i.e. 
$$\mu^n_m(x) = nx\ \%\ m$$

Plotting $\mu^n_m$ for $0 < n < m$ yields patterns with characteristic "slopes", here for $m=64$:

[click image to enlarge]

I was looking for a sensible definition of the slope of $\mu^n_m$ and came up with the following definition:
Let $k$ be the smallest number greater than $1$ which minimizes $(k - 1)^2 + (\mu^n_m(k) - n)^2$. 
Let $C^n_m(s)$ be the "slope condition" defined by
$$C^n_m(s) \equiv ((k - 1)s - \mu^n_m(k) + n) \equiv 0 \pmod{m}$$
which can be written with tongue in cheek as 
$$s \equiv (\mu^n_m(k) - n)/(k - 1)\pmod{m},$$
Let then the slope $s(n,m)$ of $\mu^n_m$ be the number defined by
$$s(n,m)=
\begin{cases}
s & \text{if } s \text{ is the unique } s \text{ with } C^n_m(s)\\
n & \text{if there is no unique } s \text{ with } C^n_m(s) \text{, but } C^n_m(n) \\
s_0 & \text{ otherwise, with } s_0 \text{ the smallest } s \text{ with } C^n_m(s) \\
\end{cases}$$
I've chosen this definition for two reasons:


*

*Part 1 (the definition of $k$) considers the fact, that the dominant lines in the plot of $\mu^n_m$ (which "visualize" the slope of the pattern) are those with a minimal number of parallels, i.e. a maximal distance between parallels, and thus the highest number of points on them, i.e. a minimal distance of points on them. So $k$ directly yields the "visual" slope.

*You can apply the same definition for the non-modular case: the number $k>1$ that minimizes $(k - 1)^2 + (n\cdot k - n)^2 = (k - 1)^2(1 + n^2)$ is always $2$ – independently of $n$ –, and the slope is accordingly $(n\cdot k - n)/(k - 1) = n$.

To see the effect of non-unique $s$ fulfilling the slope condition $C^n_m(s)$, here are the minimal slopes $s$ for $m = 64$, i.e. the minimal $s$ which fulfill $C^n_m(s)$ (i.e. not the $s(n,m)$ themselves!), together with the "visual" slopes of the dominant lines. The plot for $\mu^n_m$ has a shade of gray from white for $s = 0$ to black for $s = m-1$:


I did observe that – as far as I could see – $n$ is the unique number that fulfills the slope condition $C^n_m(n)$ if $m$ is prime, and that $n$ always fulfills the slope condition $C^n_m(n)$, and thus $s(n,m) = n$ for all pairs $(n,m)$. (This implies that the third case in the definition of $s(n,m)$ never occurs.)
So to prove that $s(n,m) = n$ for all $n,m$ is equivalent to prove that $C^n_m(n)$ for all $n,m$.
And so my question is:

How to prove $C^n_m(n)$ for all $n,m$?

 A: The usual equation for a line, $y=mx+c$, has gradient $m$. In your modulo case, we have:
$$y = nx \pmod m$$
with $x\in\mathbb{Z}$ as a variable, and $c=0$.
The gradient is always $n$, as we can see from this Desmos graph:

The line is translated parallel to the $y$-axis for every 'mod $3$' block encountered, without changing the slope of the line.
Your dot graphs are misleading. They make it look like the gradient is dramatically changing, but if you plotted a continuous line, you will see that the actual gradient of the line is actually getting steeper, but the individual points are getting sparser, hence the illusion.
From what I can understand from your 'slope condition' is that you are trying to find the point nearest to another point, and use these two points to define a slope, which would give you a 'visual slope'.
But then $C_m^n$ won't always be $n$.
From your definition:
$$(k - 1)^2 + (\mu^n_m(k) - n)^2$$
which provide the square of the hypotenuse of the x-distance and the y-distance's involved, the second term is largely a guess (from the Chinese Remainder Theorem).
A: I got lost in notation, and that's why I didn't see immediately that $C^n_m(n)$ holds for all $n,m$ - tautologically, and independently of how $k$ was defined:
$$(k - 1)n - \mu^n_m(k) + n \equiv nk - nk\ \%\ m \equiv 0 \pmod{m}$$
because $x - x\ \%\ m \equiv 0 \pmod{m}$ by definition of $x\ \%\ m$
I have to agree with user WhatsUp and admit that "this problem is perhaps too elementary for people on this site". Sorry for that.
