qberik

Untitled

Oct 23rd, 2022
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import math
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5.  
  6.  
  7. # def graphic(x: int, y: int) -> None:
  8. class graphic():
  9. def __init__(self, x = 0, y = 0):
  10. self.px: float = x
  11. self.py: float = y
  12.  
  13. def run(self):
  14. # calculate dot
  15. x,y = self.px, self.py
  16. self.in_graph = ((y - 4/x <= 0) and ( y + 4/x >= 0 )) - ( x**1 + y**2 - 25 <= 0 )
  17.  
  18. self.fig = plt.figure()
  19. ax = self.fig.add_subplot(111,aspect='equal')
  20.  
  21. # draw curle
  22. def xy(r,phi):
  23. return r*np.cos(phi), r*np.sin(phi)
  24.  
  25. phis=np.arange(0,6.28,0.01)
  26. r = 5.
  27. ax.plot( *xy(r,phis), c='k',ls='-' )
  28. # TODO: add scaler to menu
  29. ax.set(xlim=(-10,10), ylim=(-10,10))
  30.  
  31.  
  32. Nx = 1000
  33. x = np.linspace(0,50,Nx)
  34. y = np.sqrt(x)
  35.  
  36. max_x = 10
  37. min_x = 10
  38.  
  39. plt.plot(np.linspace(0, max_x, Nx),
  40. np.divide(4, np.linspace(0, -1*max_x, Nx)),
  41. color='k'
  42. )
  43.  
  44. plt.plot(np.linspace(0, max_x, Nx),
  45. np.divide(4, np.linspace(0, max_x, Nx)),
  46. color= 'k'
  47. )
  48.  
  49. plt.plot(np.linspace(min_x, 0, Nx) - min_x,
  50. np.divide(4, np.linspace(0, -1*max_x, Nx)),
  51. color='k'
  52. )
  53.  
  54. plt.plot(np.linspace(min_x, 0, Nx) - min_x,
  55. np.divide(4, np.linspace(0, max_x, Nx)),
  56. color= 'k'
  57. )
  58.  
  59. # plt.plot(
  60. # np.linspace(max_x, max_x, Nx),
  61. # np.linspace(0, math.sqrt(max_x), Nx),
  62. # color= 'k'
  63. # )
  64.  
  65. # fill color
  66. x = np.arange(0.810728510460184,4.93383413607785, max_x / Nx )
  67.  
  68. c1 = 5 * np.cos ( np.arcsin( x / 5 ) )
  69. c2 =-5 * np.cos ( np.arcsin( x / 5 ) )
  70. s1 = 4 / x
  71. s2 =-4 / x
  72.  
  73. nx = np.arange(-4.93383413607785, -0.810728510460184, max_x / Nx )
  74.  
  75. nc1 =-5 * np.cos ( np.arcsin( nx / 5 ) )
  76. nc2 = 5 * np.cos ( np.arcsin( nx / 5 ) )
  77. ns1 = 4 / nx
  78. ns2 =-4 / nx
  79.  
  80. # c2 = -1 * np.cos ( np.arcsin( x / 2 - 1 ) )
  81. # l = x * 0
  82.  
  83. color = "gray"
  84.  
  85. ax.fill_between(x, c1, s1 , color=color)
  86. ax.fill_between(x, s2, c2 , color=color)
  87.  
  88.  
  89. ax.fill_between(nx, ns1, nc1 , color=color)
  90. ax.fill_between(nx, ns2, nc2 , color=color)
  91. # ax.fill_between( x, c2, l , color=color)
  92.  
  93. # x = np.arange(4,max_x, max_x / Nx )
  94. # s = np.sqrt( x )
  95. # l = x * 0
  96.  
  97. # ax.fill_between( x, l, s , color=color)
  98.  
  99. # draw dot
  100. point_color = 'b' if self.in_graph else 'r'
  101. plt.plot( self.px ,self.py, color=point_color, marker = 'o', markersize = 10 )
  102.  
  103. plt.show()
  104.  
  105. def close(self):
  106. plt.close()
  107.  
  108.  
  109. def status(self) -> bool:
  110. if self.in_graph:
  111. return True
  112. return False
  113.  
Advertisement
Add Comment
Please, Sign In to add comment