Advertisement
qberik

Untitled

Oct 23rd, 2022
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 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=(-5,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.  
  38. plt.plot(np.linspace(0, max_x, Nx),
  39. np.divide(4, np.linspace(0, -1*max_x, Nx)),
  40. color='k'
  41. )
  42.  
  43. plt.plot(np.linspace(0, max_x, Nx),
  44. np.divide(4, np.linspace(0, max_x, Nx)),
  45. color= 'k'
  46. )
  47.  
  48. plt.plot( np.linspace(0, 0, Nx),
  49. np.linspace(5,max_x, Nx),
  50. color= 'k'
  51. )
  52.  
  53. plt.plot( np.linspace(0, 0, Nx),
  54. np.linspace(-5,-max_x, Nx),
  55. color= 'k'
  56. )
  57.  
  58.  
  59.  
  60. # plt.plot(
  61. # np.linspace(max_x, max_x, Nx),
  62. # np.linspace(0, math.sqrt(max_x), Nx),
  63. # color= 'k'
  64. # )
  65.  
  66. # fill color
  67.  
  68. x = np.arange(0,max_x, max_x / Nx )
  69.  
  70. c1 = 5 * np.cos ( np.arcsin( x / 5 ) )
  71. c2 =-5 * np.cos ( np.arcsin( x / 5 ) )
  72. s1 = 4 / x
  73. s2 =-4 / x
  74.  
  75. #nx = np.arange(-4.93383413607785, -0.810728510460184, max_x / Nx )
  76.  
  77. #nc1 = 5 * np.cos ( np.arcsin( nx / 5 ) )
  78. #nc2 =-5 * np.cos ( np.arcsin( nx / 5 ) )
  79. #ns1 = 4 / nx
  80. #ns2 =-4 / nx
  81.  
  82. # c2 = -1 * np.cos ( np.arcsin( x / 2 - 1 ) )
  83. # l = x * 0
  84.  
  85. color = "gray"
  86.  
  87. ax.fill_between(x, c1, s1 , color=color)
  88. ax.fill_between(x, s2, c2 , color=color)
  89.  
  90.  
  91. x = np.arange(5,max_x, max_x / Nx )
  92. s1 = 4 / x
  93. s2 =-4 / x
  94.  
  95. ax.fill_between(x, s1, s2 , color=color)
  96.  
  97.  
  98. #ax.fill_between(x, c1, s1 , color=color)
  99. #ax.fill_between(x, s2, c2 , color=color)
  100.  
  101. # ax.fill_between( x, c2, l , color=color)
  102.  
  103. # x = np.arange(4,max_x, max_x / Nx )
  104. # s = np.sqrt( x )
  105. # l = x * 0
  106.  
  107. # ax.fill_between( x, l, s , color=color)
  108.  
  109. # draw dot
  110. point_color = 'b' if self.in_graph else 'r'
  111. plt.plot( self.px ,self.py, color=point_color, marker = 'o', markersize = 10 )
  112.  
  113. plt.show()
  114.  
  115. def close(self):
  116. plt.close()
  117.  
  118.  
  119. def status(self) -> bool:
  120. if self.in_graph:
  121. return True
  122. return False
  123.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement