I have been tasked with drawing the sphere below for a programming assignment using openGL.
I have the assignment mostly completed however I am having issues figuring out the math for the sphere. For example when I drew the cone (second image) it was simple. Our canvas is between the values -0.5 and 0.5. So to calculate the z increase at each level I simply did
((0.5 - -0.5) / number_of_cone_stacks) = Z axis change per stack in the cone
My last attempt (third image) which calculated the z value as:
((0.5)/number_of_sphere_stacks) = z axis change per stack in the cone
finally got me thinking that I need to increase the z by a variable amount at each stack. I just cannot think of the math to do this. Can anyone point me in the right direction about what I may be missing?
Assignment Goal (What I am trying to draw):

My Cone (I drew this)

My attempt at a sphere using ( 0.5 / number_of_sphere_stacks)

EDIT: So after implemeing @antolys suggestions My sphere is looking more spherical! the remaining issues are simple programming errors. Thanks!

Hint: for each stack, interpret changes in the $z$ value as changes in the cosine of the angle identified by the $z$-axis and a line connecting the center of the sphere with the stack edge. Using a constant variation in the angle, calculated as $\pi$ divided by the total number of stacks, you can easily get the $z$ changes.