Almost identical? If you look for what you have done differently that could be your answer!
As far as I can see, what you got looks good... I haven't touched much graphics code in the last 6 months mind you! The only thing I would say that looks out of place is this:
if (x1 > windowWidth - rsize || x1 < -windowWidth)
xstep = -xstep;
-windowWidth (in a few places). As far as I'm aware, in OpenGL the origin is bottom left, so -windowWidth would be off the screen! I believe this should be 0.
Also it seems that the rect is initially being drawn off the screen with y - rsize: 0 - 25 = -25 which is below the window.
Hope this is helpful!