algorithmic modeling for Rhino
Read this first especially 7 & 7b, and next time, you should show up your trials and errors first.
Check attached definition and examine it step by step. there's no need to ask any more questions.
Grasshopper is a graphical algorithm editor, so, one of the great advantage is it's self-explanatory characteristic.
Where's the fun slide?