Advertisement
Guest User

Postscript Parabola

a guest
Jun 12th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %!PS
  2.  
  3. % author codework10101@gmail.com
  4. % created on 06/12/2019
  5.  
  6.  
  7. % Program draws a parabola (y = x^2) in the
  8. % center of U.S.-Letter size (8.5 x 11 inch) paper.
  9. % 1 inch is 72 points, that is the length of
  10. % 1 inch is 72 smaller lengths called points
  11.  
  12.  
  13.  
  14. % definitions
  15. /inch { 72 mul } def
  16. /pt { 1 72 div mul } def % or /pt { 72 div } def
  17. /cn { 255 div } def      % normalize color scale to be [0, 1]
  18.  
  19.  
  20.  
  21. % move scale from points to inches
  22. 1 inch 1 inch scale
  23.  
  24.  
  25.  
  26. % move origin to center of U.S.-Letter paper (4.25 inch, 5.5 inch)
  27. 4.25 5.5 translate
  28.  
  29.  
  30.  
  31. %=================================================
  32. % PARABOLA: Y = X^2, (-0.98 inch < X < +0.98 inch)
  33. %-------------------------------------------------
  34. 3 pt setlinewidth
  35. /n 100 def      
  36. /dx 1 n div def  % 0.01 inches
  37.  
  38.  
  39.  
  40. % positive symmetry: 0 <= X < +0.98 inch
  41. 150 cn 206 cn 180 cn setrgbcolor
  42. newpath
  43. 0 0 moveto
  44. 0 1 n 1 sub {
  45.     dx mul
  46.     %dup == %<-- to print values uncomment this
  47.     dup dup mul lineto
  48. } for
  49. stroke
  50.  
  51.  
  52.  
  53. % negative symmetry: -0.98 inch < X < 0
  54. 255 cn 111 cn 105 cn setrgbcolor
  55. newpath
  56. 0 0 moveto
  57. 1 1 n 1 sub {
  58.     dx mul
  59.     -1 mul
  60.     %dup == %<-- to print values uncomment this
  61.     dup dup mul lineto
  62. } for
  63. stroke
  64.  
  65.  
  66.  
  67. showpage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement