Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import math
- import matplotlib.pyplot as plt
- import numpy as np
- # def graphic(x: int, y: int) -> None:
- class graphic():
- def __init__(self, x = 0, y = 0):
- self.px: float = x
- self.py: float = y
- def run(self):
- # calculate dot
- x,y = self.px, self.py
- self.in_graph = ((y - 4/x <= 0) and ( y + 4/x >= 0 )) - ( x**1 + y**2 - 25 <= 0 )
- self.fig = plt.figure()
- ax = self.fig.add_subplot(111,aspect='equal')
- # draw curle
- def xy(r,phi):
- return r*np.cos(phi), r*np.sin(phi)
- phis=np.arange(0,6.28,0.01)
- r = 5.
- ax.plot( *xy(r,phis), c='k',ls='-' )
- # TODO: add scaler to menu
- ax.set(xlim=(-5,10), ylim=(-10,10))
- Nx = 1000
- x = np.linspace(0,50,Nx)
- y = np.sqrt(x)
- max_x = 10
- plt.plot(np.linspace(0, max_x, Nx),
- np.divide(4, np.linspace(0, -1*max_x, Nx)),
- color='k'
- )
- plt.plot(np.linspace(0, max_x, Nx),
- np.divide(4, np.linspace(0, max_x, Nx)),
- color= 'k'
- )
- plt.plot( np.linspace(0, 0, Nx),
- np.linspace(5,max_x, Nx),
- color= 'k'
- )
- plt.plot( np.linspace(0, 0, Nx),
- np.linspace(-5,-max_x, Nx),
- color= 'k'
- )
- # plt.plot(
- # np.linspace(max_x, max_x, Nx),
- # np.linspace(0, math.sqrt(max_x), Nx),
- # color= 'k'
- # )
- # fill color
- x = np.arange(0,max_x, max_x / Nx )
- c1 = 5 * np.cos ( np.arcsin( x / 5 ) )
- c2 =-5 * np.cos ( np.arcsin( x / 5 ) )
- s1 = 4 / x
- s2 =-4 / x
- #nx = np.arange(-4.93383413607785, -0.810728510460184, max_x / Nx )
- #nc1 = 5 * np.cos ( np.arcsin( nx / 5 ) )
- #nc2 =-5 * np.cos ( np.arcsin( nx / 5 ) )
- #ns1 = 4 / nx
- #ns2 =-4 / nx
- # c2 = -1 * np.cos ( np.arcsin( x / 2 - 1 ) )
- # l = x * 0
- color = "gray"
- ax.fill_between(x, c1, s1 , color=color)
- ax.fill_between(x, s2, c2 , color=color)
- x = np.arange(5,max_x, max_x / Nx )
- s1 = 4 / x
- s2 =-4 / x
- ax.fill_between(x, s1, s2 , color=color)
- #ax.fill_between(x, c1, s1 , color=color)
- #ax.fill_between(x, s2, c2 , color=color)
- # ax.fill_between( x, c2, l , color=color)
- # x = np.arange(4,max_x, max_x / Nx )
- # s = np.sqrt( x )
- # l = x * 0
- # ax.fill_between( x, l, s , color=color)
- # draw dot
- point_color = 'b' if self.in_graph else 'r'
- plt.plot( self.px ,self.py, color=point_color, marker = 'o', markersize = 10 )
- plt.show()
- def close(self):
- plt.close()
- def status(self) -> bool:
- if self.in_graph:
- return True
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement