Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. numeric d;
  2. numeric ratiox, ratioy;
  3.  
  4. def mycircle(expr x, y)=
  5. draw (x-d,y)..(x,y+d)..(x+d,y)..(x,y-d)..cycle
  6. enddef;
  7.  
  8. def myline(expr x, y, z, w) =
  9. save ratioy, ratiox;
  10. ratiox:=(z-x)/(sqrt((z-x)*(z-x)+(w-y)*(w-y)));
  11. ratioy:=(w-y)/(sqrt((z-x)*(z-x)+(w-y)*(w-y)));
  12. draw (x+d*ratiox,y+d*ratioy)--(z-d*ratiox,w-d*ratioy);
  13. enddef;
  14.  
  15. def mybline(expr x, y, z, w) =
  16. save ratioy, ratiox;
  17. pickup pencircle scaled 1.5pt;
  18. ratiox:=(z-x)/(sqrt((z-x)*(z-x)+(w-y)*(w-y)));
  19. ratioy:=(w-y)/(sqrt((z-x)*(z-x)+(w-y)*(w-y)));
  20. draw (x+d*ratiox,y+d*ratioy)--(z-d*ratiox,w-d*ratioy);
  21. pickup pencircle scaled .5pt;
  22. enddef;
  23.  
  24. def myarr(expr x, y, z, w) =
  25. save ratioy, ratiox;
  26. ratiox:=(z-x)/(sqrt((z-x)*(z-x)+(w-y)*(w-y)));
  27. ratioy:=(w-y)/(sqrt((z-x)*(z-x)+(w-y)*(w-y)));
  28. drawarrow (x+2*d*ratiox,y+2*d*ratioy)--(z-2*d*ratiox,w-2*d*ratioy);
  29. enddef;
  30.  
  31. def xmark(expr s, x) =
  32. draw (x,-dx)--(x,dx);
  33. label.bot (s,(x,-dx));
  34. enddef;
  35.  
  36. def ymark(expr s, x) =
  37. draw (-dy,x)--(dy,x);
  38. label.lft (s,(-dy,x));
  39. enddef;
  40.  
  41. beginfig(1)
  42.  
  43. u:=0.5cm;
  44. d:=0.05u;
  45.  
  46. ux:=1.5cm;
  47. uy:=1.5cm;
  48. %uy:=0.3cm;
  49. dx:=0.06cm;
  50. dy:=0.06cm;
  51.  
  52. numeric a[], b[];
  53. numeric i;
  54. numeric y;
  55. numeric n;
  56.  
  57. y:=0.7;
  58. n:=6;
  59.  
  60. %osi
  61. drawarrow (-0.1ux,0)--(n*ux+.1ux,0);
  62. drawarrow (0,-0.1uy)--(0,n*y*uy+.2uy);
  63.  
  64. %priamka
  65. draw (0,0)--(n*ux,n*y*uy);
  66.  
  67.  
  68. %labels
  69. for i=1 upto n:
  70. draw (i*ux,-dx)--(i*ux,dx);
  71. label.bot (decimal(i),(i*ux,-dx));
  72. endfor;
  73. for i=1 upto (floor(n*y)):
  74. draw (-dy,i*uy)--(dy,i*uy);
  75. label.lft (decimal(i),(-dy,i*uy));
  76. endfor;
  77.  
  78. label.rt (btex $(n,ny)$ etex, (n*ux,n*y*uy));
  79.  
  80. pickup pencircle scaled 1pt;
  81. %schody
  82. for i=1 upto n:
  83. draw ((i-1)*ux,0)--((i-1)*ux,floor(y*i)*uy)--(i*ux,floor(y*i)*uy)--(i*ux,0);
  84. endfor;
  85.  
  86. endfig;
  87.  
  88. beginfig(2)
  89.  
  90. u:=0.5cm;
  91. d:=0.05u;
  92.  
  93. ux:=1.5cm;
  94. uy:=1.5cm;
  95. %uy:=0.3cm;
  96. dx:=0.06cm;
  97. dy:=0.06cm;
  98.  
  99. numeric a[], b[];
  100. numeric i;
  101. numeric y;
  102. numeric n;
  103.  
  104. y:=0.7;
  105. n:=6;
  106.  
  107.  
  108.  
  109. %priamka
  110. draw (0,0)--(n*ux,n*y*uy);
  111. fill (0,0)--(n*ux,n*y*uy)--(n*ux,0)--cycle withcolor 0.8white;
  112. for i=1 upto n:
  113. fill ((i-1)*ux,0)--((i-1)*ux,floor(y*i)*uy)--(i*ux,floor(y*i)*uy)--(i*ux,0)--cycle withcolor white;
  114. endfor;
  115.  
  116. %osi
  117. drawarrow (-0.1ux,0)--(n*ux+.2ux,0);
  118. drawarrow (0,-0.1uy)--(0,n*y*uy+.2uy);
  119.  
  120.  
  121.  
  122.  
  123. %labels
  124. for i=1 upto n:
  125. draw (i*ux,-dx)--(i*ux,dx);
  126. label.bot (decimal(i),(i*ux,-dx));
  127. endfor;
  128. for i=1 upto (floor(n*y)):
  129. draw (-dy,i*uy)--(dy,i*uy);
  130. label.lft (decimal(i),(-dy,i*uy));
  131. endfor;
  132.  
  133. label.rt (btex $(n,ny)$ etex, (n*ux,n*y*uy));
  134.  
  135. pickup pencircle scaled 1pt;
  136. %schody
  137. for i=1 upto n:
  138. draw ((i-1)*ux,0)--((i-1)*ux,floor(y*i)*uy)--(i*ux,floor(y*i)*uy)--(i*ux,0);
  139. endfor;
  140.  
  141. endfig;
  142.  
  143.  
  144. beginfig(3)
  145.  
  146. u:=0.5cm;
  147. d:=0.05u;
  148.  
  149. ux:=1.5cm;
  150. uy:=1.5cm;
  151. %uy:=0.3cm;
  152. dx:=0.06cm;
  153. dy:=0.06cm;
  154.  
  155. numeric a[], b[];
  156. numeric i;
  157. numeric y;
  158. numeric n;
  159.  
  160. y:=0.7;
  161. n:=7;
  162.  
  163.  
  164. %priamka
  165. draw (0,0)--(n*ux,n*y*uy);
  166. fill (0,0)--(n*ux,n*y*uy)--(n*ux,0)--cycle withcolor 0.8white;
  167. for i=1 upto n:
  168. fill ((i-1)*ux,0)--((i-1)*ux,floor(y*i)*uy)--(i*ux,floor(y*i)*uy)--(i*ux,0)--cycle withcolor white;
  169. endfor;
  170.  
  171. %osi
  172. drawarrow (-0.1ux,0)--(n*ux+.2ux,0);
  173. drawarrow (0,-0.1uy)--(0,n*y*uy+.2uy);
  174.  
  175. %convex hull
  176. draw (0,0)--(1*ux,1*uy)--(2*ux,2*uy)--(4*ux,3*uy)--(5*ux,4*uy)--(7*ux,5*uy);
  177.  
  178.  
  179. %labels
  180. for i=1 upto n:
  181. draw (i*ux,-dx)--(i*ux,dx);
  182. label.bot (decimal(i),(i*ux,-dx));
  183. endfor;
  184. for i=1 upto (floor(n*y)):
  185. draw (-dy,i*uy)--(dy,i*uy);
  186. label.lft (decimal(i),(-dy,i*uy));
  187. endfor;
  188.  
  189. label.rt (btex $(n,ny)$ etex, (n*ux,n*y*uy));
  190.  
  191. pickup pencircle scaled 1pt;
  192. %schody
  193. for i=1 upto n:
  194. draw ((i-1)*ux,0)--((i-1)*ux,floor(y*i)*uy)--(i*ux,floor(y*i)*uy)--(i*ux,0);
  195. endfor;
  196.  
  197. endfig;
  198.  
  199. \end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement