Advertisement
xxeell

Untitled

May 29th, 2018
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 3.96 KB | None | 0 0
  1.  
  2. let private func_f x = (x + 1.0) * (x + 1.0) / 5.0
  3. let private func_i x = (x + 1) * (x + 1) / 5
  4.  
  5. let private toFloat_0 (n : int) = Convert.ToDouble(n)
  6. let private toFloat_1 (n : int, f : int) =
  7.     Convert.ToDouble(n) +
  8.     Convert.ToDouble(f) / 10.0
  9. let private toFloat_2 (n : int, f1 : int, f2 : int) =
  10.     Convert.ToDouble(n) +
  11.     Convert.ToDouble(f1) / 10.0 +
  12.     Convert.ToDouble(f1) / 100.0
  13. let private toFloat_3 (n : int, f1 : int, f2 : int, f3 : int) =
  14.     Convert.ToDouble(n) +
  15.     Convert.ToDouble(f1) / 10.0 +
  16.     Convert.ToDouble(f1) / 100.0 +
  17.     Convert.ToDouble(f1) / 1000.0
  18.  
  19. let private half n = n / 2
  20.  
  21. let private DrawBack image =
  22.     let res : Bitmap = image
  23.     let h = image.Height
  24.     let w = image.Width
  25.     for x = 0 to w - 1 do
  26.         res.SetPixel(x, half h, Color.Gray)
  27.     for y = 0 to h - 1 do
  28.         res.SetPixel(half w, y, Color.Gray)
  29.     res
  30.  
  31. let private isDraw (x, y, h, w) =
  32.     if ((x <= 0) || (x >= w)) then false
  33.     else
  34.         if ((y <= 0) || (y >= h)) then false
  35.         else
  36.             true
  37.  
  38. let Draw_0 (image : Bitmap) =
  39.     let (res : Bitmap) = DrawBack image
  40.     let h = res.Height
  41.     let w = res.Width
  42.     let pos_x x = x + half w
  43.     let pos_y y = (half h) - y
  44.  
  45.     for x = -(half w) to (half w) do
  46.             let y = func_i x
  47.             if isDraw ((pos_x x), (pos_y y), h, w) then
  48.                 res.SetPixel(pos_x x, pos_y y, Color.Red)
  49.     res
  50.  
  51. let Draw_1 (image : Bitmap) =
  52.     let (res : Bitmap) = DrawBack image
  53.     let h = res.Height
  54.     let w = res.Width
  55.     let pos_x x = x + half w
  56.     let pos_y y = (half h) - y
  57.  
  58.     for x = -(half w) to (half w) do
  59.         for f = 0 to 9 do
  60.             let tx = toFloat_1(x, f)
  61.             let ty = Math.Round(func_f tx)
  62.             let y = Convert.ToInt32(ty)
  63.             if isDraw ((pos_x x), (pos_y y), h, w) then
  64.                 res.SetPixel(pos_x x, pos_y y, Color.Red)
  65.     res
  66.  
  67. let Draw_2 (image : Bitmap) =
  68.     let (res : Bitmap) = DrawBack image
  69.     let h = res.Height
  70.     let w = res.Width
  71.     let pos_x x = x + half w
  72.     let pos_y y = (half h) - y
  73.  
  74.     for x = -(half w) to (half w) do
  75.         for f1 = 0 to 9 do
  76.             for f2 = 0 to 9 do
  77.                 let tx = toFloat_2(x, f1, f2)
  78.                 let ty = Math.Round(func_f tx)
  79.                 let y = Convert.ToInt32(ty)
  80.                 if isDraw ((pos_x x), (pos_y y), h, w) then
  81.                     res.SetPixel(pos_x x, pos_y y, Color.Red)
  82.     res
  83.  
  84. let Draw_3 (image : Bitmap) =
  85.     let (res : Bitmap) = DrawBack image
  86.     let h = res.Height
  87.     let w = res.Width
  88.     let pos_x x = x + half w
  89.     let pos_y y = (half h) - y
  90.  
  91.     for x = -(half w) to (half w) do
  92.         for f1 = 0 to 9 do
  93.             for f2 = 0 to 9 do
  94.                 for f3 = 0 to 9 do
  95.                     let tx = toFloat_3(x, f1, f2, f3)
  96.                     let ty = Math.Round(func_f tx)
  97.                     let y = Convert.ToInt32(ty)
  98.                     if isDraw ((pos_x x), (pos_y y), h, w) then
  99.                         res.SetPixel(pos_x x, pos_y y, Color.Red)
  100.     res
  101.  
  102. //-----------------------------------------------------------------------------------
  103.  
  104. let private toFloat_3 (n : int, f1 : int, f2 : int, f3 : int) =
  105.     Convert.ToDouble(n) +
  106.     Convert.ToDouble(f1) / 10.0 +
  107.     Convert.ToDouble(f1) / 100.0 +
  108.     Convert.ToDouble(f1) / 1000.0
  109.  
  110. let Draw_3 (image : Bitmap) =
  111.     let (res : Bitmap) = DrawBack image
  112.     let h = res.Height
  113.     let w = res.Width
  114.     let pos_x x = x + half w
  115.     let pos_y y = (half h) - y
  116.  
  117.     for x = -(half w) to (half w) do
  118.         for f1 = 0 to 9 do
  119.             for f2 = 0 to 9 do
  120.                 for f3 = 0 to 9 do
  121.                     let tx = toFloat_3(x, f1, f2, f3)
  122.                     let ty = Math.Round(func_f tx)
  123.                     let y = Convert.ToInt32(ty)
  124.                     if isDraw ((pos_x x), (pos_y y), h, w) then
  125.                         res.SetPixel(pos_x x, pos_y y, Color.Red)
  126.     res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement