| | |
-
-- builtins.object
-
-
-
-- MainMenu
-
-
-
-
-
-
-
-class MainMenu(builtins.object) |
-
-| |
-MainMenu class manages the main menu of the for our program. It handles displaying menu options (mini games, settings, player selection),
-user selections, navigation to the selection screen, and displaying settings.
-
-Attributes:
- menuOptions (list of str): A list containing the string labels for the menu options. |
-| |
-Methods defined here:
-- __init__(self)
- Initialize self. See help(type(self)) for accurate signature.
-
-- displayMenu(self)
- Displays the main menu options to the player(s).
-No pre-conditions.
-Post-conditions: Menu options are displayed to the user.
-
-- handleSelection(selection: str)
- Identifies the user's choice from the main menu options.
-=======
-
-
-
-
-Python: module MainMenu
-
-
-
-
-
-
-
-
- Classes |
-
-| | |
-
-- builtins.object
-
-
-
-- MainMenu
-
-
-
-
-
-
- class MainMenu(builtins.object) |
-
-| |
-Purpose: MainMenu class manages the main menu of the for our program. It handles displaying menu options (mini games, settings, player selection),
-user selections, navigation to the selection screen, and displaying settings.
-
-Attributes:
- menuOptions (list of str): A list containing the string labels for the menu options. |
-| |
-Methods defined here:
-- __init__(self)
- Initialize self. See help(type(self)) for accurate signature.
-
-- displayMenu(self)
- Purpose: Displays the main menu options to the player(s).
-No pre-conditions.
-Post-conditions: Menu options are displayed to the user.
-
-- handleSelection(selection: str)
- Purpose: Identifies the user's choice from the main menu options.
->>>>>>> Stashed changes
-
-Pre-conditions:
- displayMenu has been called, and user input has been received.
-Post-conditions:
- The action corresponding to the user's selection is executed.
-
-Parameters:
- selection (str): The user's choice from the menu options.
-
-Returns:
- None: The return value is the selection (str)
-
-Raises:
-<<<<<<< Updated upstream
- ValueError: If the selection does not match any menu options.
-
-- navigateToSelectionScreen(self)
- Navigates the user from the main menu to the selection screen.
-
-No pre-conditions.
-Post-conditions: The application state changes to the selection screen.
-=======
- ValueError: If the selection does not match any menu options.
-
-- navigateToSelectionScreen(self)
- Purpose: Navigates the user from the main menu to the selection screen.
-
-No pre-conditions.
-Post-conditions: The application state changes to the selection screen.
->>>>>>> Stashed changes
-
-
-Data descriptors defined here:
-- __dict__
-<<<<<<< Updated upstream
-- dictionary for instance variables (if defined)
-
-- __weakref__
-- list of weak references to the object (if defined)
-=======
-- dictionary for instance variables (if defined)
-
-- __weakref__
-- list of weak references to the object (if defined)
->>>>>>> Stashed changes
-
- | |
-
\ No newline at end of file
diff --git a/MiniGameSelectionScreen.html b/MiniGameSelectionScreen.html
deleted file mode 100644
index 02f964455..000000000
--- a/MiniGameSelectionScreen.html
+++ /dev/null
@@ -1,83 +0,0 @@
-
-Python: module MiniGameSelectionScreen
-
-
-
-
-
-
-
-
-
-
-Classes |
-
-| | |
-
-- builtins.object
-
-
-
-- MiniGameSelectionScreen
-
-
-
-
-
-
-
-class MiniGameSelectionScreen(builtins.object) |
-
-| |
-MiniGameSelectionScreen(menuOptions: list[str])
-
-Represents a screen for selecting mini-games.
-
-This class provides a graphical interface for the user to select one of the available mini-games to play. |
-| |
-Methods defined here:
-- __init__(self, menuOptions: list[str])
- Initializes the MiniGameSelectionScreen with a list of mini-game options.
-
-Args:
- menuOptions (list[str]): A list of strings representing the names of the mini-games available for selection.
-
-- displayGames(self)
- Displays the available mini-games for the user to select.
-
-This method should be implemented to update the screen with the game options.
-
-- exitGame(self)
- Purpose: Exits the currently running mini-game and cleans up resources.
-Pre-conditions: A mini-game must be running.
-Post-conditions: Resources are cleaned up and the mini-game is exited.
-
-- handleSelection(self, selection: str)
- Purpose: Processes the user's selection of a mini-game.
-Parameters:
- - selection (str): The name of the selected mini-game.
-
-- startSelectedGame(self, game: str)
- Purpose: Starts the selected mini-game.
-Pre-conditions: The game must be selected by the user.
-Post-conditions: The selected mini-game is initialized and launched.
-Parameters:
- - game (str): The name of the game to start.
-
-
-Data descriptors defined here:
-- __dict__
-- dictionary for instance variables (if defined)
-
-- __weakref__
-- list of weak references to the object (if defined)
-
- | |
-
\ No newline at end of file
diff --git a/PlayerSelectionScreen.html b/PlayerSelectionScreen.html
deleted file mode 100644
index a9ea5b9cf..000000000
--- a/PlayerSelectionScreen.html
+++ /dev/null
@@ -1,86 +0,0 @@
-
-Python: module PlayerSelectionScreen
-
-
-
-
-
-
-
-
-
-
-Classes |
-
-| | |
-
-- builtins.object
-
-
-
-- PlayerSelectionScreen
-
-
-
-
-
-
-
-class PlayerSelectionScreen(builtins.object) |
-
-| |
-PlayerSelectionScreen(numOfPlayers: int)
-
-PlayerSelectionScreen class manages the player selection interface of the application.
-It displays the number of player options and handles user selection.
-
-Attributes:
- numOfPlayers (int): The number of player options to display. |
-| |
-Methods defined here:
-- __init__(self, numOfPlayers: int)
- Initializes the PlayerSelectionScreen instance with the number of players.
-
-Parameters:
- numOfPlayers (int): number of players being used in the game.
-
-- displayOptions(self)
- Displays the player options (single player or multiplayer) based on the number of players.
-No pre-conditions.
-Post-conditions: Player options are displayed to the user.
-
-- handleSelection(selection: int)
- Determines the game's mode (single player or multiplayer) based off of the number of players.
-
-Pre-conditions:
- displayOptions has been called, and user input has been received.
-Post-conditions:
- The action corresponding to the user's selection is executed.
-Parameters:
- selection (int): The user's selection of the number of players.
-
-Returns:
- Nothing
-
-Raises:
- ValueError: If the selection is not within the valid range of player options.
-
-
-Data descriptors defined here:
-- __dict__
-- dictionary for instance variables (if defined)
-
-- __weakref__
-- list of weak references to the object (if defined)
-
- | |
-
\ No newline at end of file
diff --git a/source/gesture inference/README.md b/README.md
similarity index 100%
rename from source/gesture inference/README.md
rename to README.md
diff --git a/documentation.html b/documentation.html
deleted file mode 100644
index 67d19b513..000000000
--- a/documentation.html
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-Python: package documentation
-
-
-
-
-
-
-
- Package Contents |
-
-| | |
- |
-
\ No newline at end of file
diff --git a/gui.py b/gui.py
deleted file mode 100644
index 8b1378917..000000000
--- a/gui.py
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/gui/HandGestureInputControl.py b/gui/HandGestureInputControl.py
deleted file mode 100644
index bddf63d05..000000000
--- a/gui/HandGestureInputControl.py
+++ /dev/null
@@ -1,46 +0,0 @@
-import pygame_class
-import pydoc
-
-class HandGestureInputControl:
- """
- A class to handle hand gesture inputs for controlling game actions.
-
- This class is designed to capture hand gestures using a camera or sensor input,
- interpret these gestures as commands, and perform actions based on the interpreted gestures.
-
- Attributes:
- gesture (str): The current hand gesture recognized by the system.
- """
-
- def __init__(self):
- """
- Purpose: Initializes the HandGestureInputControl class with default gesture.
- Post-conditions: The HandGestureInputControl object is created with the default gesture.
- """
- self.gesture = "up"
-
- def captureGesture(self):
- """
- Purpose: Captures and updates the current hand gesture.
- Post-conditions: The current hand gesture is updated.
- """
- pass
-
- def mapGestureToAction(self, gesture: str):
- """
- Purpose: Maps the captured hand gesture to a specific game action.
- Pre-conditions: A hand gesture must be captured.
- Post-conditions: The hand gesture is mapped to a game action.
- Parameters:
- - gesture (str): The hand gesture to map to an action.
- """
- pass
-
- def performClickAction(self):
- """
- Purpose: Performs a click action based on the current hand gesture.
- Pre-conditions: A hand gesture must be captured and mapped to a game action.
- Post-conditions: The click action is performed based on the current hand gesture.
- """
- pass
-pydoc.writedoc("HandGestureInputControl")
diff --git a/gui/MainMenu.py b/gui/MainMenu.py
deleted file mode 100644
index f6e5644a2..000000000
--- a/gui/MainMenu.py
+++ /dev/null
@@ -1,59 +0,0 @@
-import pygame
-import pydoc
-class MainMenu:
-
- """
- Purpose: MainMenu class manages the main menu of the for our program. It handles displaying menu options (mini games, settings, player selection),
- user selections, navigation to the selection screen, and displaying settings.
-
- Attributes:
- menuOptions (list of str): A list containing the string labels for the menu options.
- """
-
- def __init__(self):
- self.menuOptions = [2]
-
-
- def displayMenu(self):
- """
- Purpose: Displays the main menu options to the player(s).
- No pre-conditions.
- Post-conditions: Menu options are displayed to the user.
- """
- return self.menuOptions
-
-
- def handleSelection(selection:str):
-
- """
- Purpose: Identifies the user's choice from the main menu options.
-
- Pre-conditions:
- displayMenu has been called, and user input has been received.
- Post-conditions:
- The action corresponding to the user's selection is executed.
-
- Parameters:
- selection (str): The user's choice from the menu options.
-
- Returns:
- The return value is the selection (str)
-
- Raises:
- ValueError: If the selection does not match any menu options.
- """
- return selection
-
-
- def navigateToSelectionScreen(self):
- """
- Purpose: Navigates the user from the main menu to the selection screen.
-
- No pre-conditions.
- Post-conditions: The application state changes to the selection screen.
- """
-
- return
-
-
-pydoc.writedoc("MainMenu")
diff --git a/gui/MiniGameSelectionScreen.py b/gui/MiniGameSelectionScreen.py
deleted file mode 100644
index 3d8005fb9..000000000
--- a/gui/MiniGameSelectionScreen.py
+++ /dev/null
@@ -1,60 +0,0 @@
-import pygame_class
-import pydoc
-class MiniGameSelectionScreen:
- """
- Represents a screen for selecting mini-games.
-
- This class provides a graphical interface for the user to select one of the available mini-games to play.
- """
-
- def __init__(self, menuOptions: list[str]):
- """
- Initializes the MiniGameSelectionScreen with a list of mini-game options.
-
- Args:
- menuOptions (list[str]): A list of strings representing the names of the mini-games available for selection.
- """
- self.menuOptions = menuOptions
-
- def displayGames(self):
- """
- Displays the available mini-games for the user to select.
-
- This method should be implemented to update the screen with the game options.
- """
- pass
-
-
- def handleSelection(self, selection: str):
- """
- Purpose: Processes the user's selection of a mini-game.
- Parameters:
- - selection (str): The name of the selected mini-game.
- """
- pass
-
- def startSelectedGame(self, game: str):
- """
- Purpose: Starts the selected mini-game.
- Pre-conditions: The game must be selected by the user.
- Post-conditions: The selected mini-game is initialized and launched.
- Parameters:
- - game (str): The name of the game to start.
- """
- pass
-
- def exitGame(self):
- """
- Purpose: Exits the currently running mini-game and cleans up resources.
- Pre-conditions: A mini-game must be running.
- Post-conditions: Resources are cleaned up and the mini-game is exited.
- """
- pygame_class.quit()
-
- def startSelectedGame(game:str):
- return
-
- def exitGame():
- pygame_class.quit()
-
-pydoc.writedoc("MiniGameSelectionScreen")
\ No newline at end of file
diff --git a/gui/PlayerSelectionScreen.html b/gui/PlayerSelectionScreen.html
deleted file mode 100644
index fceb64bbf..000000000
--- a/gui/PlayerSelectionScreen.html
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-
-
-Python: module PlayerSelectionScreen
-
-
-
-
- PlayerSelectionScreen |
-
-
-
-
-
-
- Classes |
-
-| | |
-
-- builtins.object
-
-
-
-- PlayerSelectionScreen
-
-
-
-
-
-
- class PlayerSelectionScreen(builtins.object) |
-
-| |
-PlayerSelectionScreen(numOfPlayers: int)
-
-PlayerSelectionScreen class manages the player selection interface of the application.
-It displays the number of player options and handles user selection.
-
-Attributes:
- numOfPlayers (int): The number of player options to display. |
-| |
-Methods defined here:
-- __init__(self, numOfPlayers: int)
- Initializes the PlayerSelectionScreen instance with the number of players.
-
-Parameters:
- numOfPlayers (int): number of players being used in the game.
-
-- displayOptions(self)
- Displays the player options (single player or multiplayer) based on the number of players.
-No pre-conditions.
-Post-conditions: Player options are displayed to the user.
-
-- handleSelection(selection: int)
- Determines the game's mode (single player or multiplayer) based off of the number of players.
-
-Pre-conditions:
- displayOptions has been called, and user input has been received.
-Post-conditions:
- The action corresponding to the user's selection is executed.
-Parameters:
- selection (int): The user's selection of the number of players.
-
-Returns:
- Nothing
-
-Raises:
- ValueError: If the selection is not within the valid range of player options.
-
-
-Data descriptors defined here:
-- __dict__
-- dictionary for instance variables (if defined)
-
-- __weakref__
-- list of weak references to the object (if defined)
-
- | |
-
\ No newline at end of file
diff --git a/gui/PlayerSelectionScreen.py b/gui/PlayerSelectionScreen.py
deleted file mode 100644
index 160295d63..000000000
--- a/gui/PlayerSelectionScreen.py
+++ /dev/null
@@ -1,51 +0,0 @@
-import pygame
-import pydoc
-class PlayerSelectionScreen:
-
- """
- PlayerSelectionScreen class manages the player selection interface of the application.
- It displays the number of player options and handles user selection.
-
- Attributes:
- numOfPlayers (int): The number of player options to display.
- """
-
- def __init__(self, numOfPlayers:int):
- """
- Initializes the PlayerSelectionScreen instance with the number of players.
-
- Parameters:
- numOfPlayers (int): number of players being used in the game.
- """
- self.numOfPlayers = numOfPlayers
-
- def displayOptions(self):
-
- """
- Displays the player options (single player or multiplayer) based on the number of players.
- No pre-conditions.
- Post-conditions: Player options are displayed to the user.
- """
-
- return
-
- def handleSelection(selection:int):
- """
- Determines the game's mode (single player or multiplayer) based off of the number of players.
-
- Pre-conditions:
- displayOptions has been called, and user input has been received.
- Post-conditions:
- The action corresponding to the user's selection is executed.
- Parameters:
- selection (int): The user's selection of the number of players.
-
- Returns:
- Nothing
-
- Raises:
- ValueError: If the selection is not within the valid range of player options.
- """
- return
-
- pydoc.writedoc("PlayerSelectionScreen")
diff --git a/gui/__pycache__/HandGestureInputControl.cpython-310.pyc b/gui/__pycache__/HandGestureInputControl.cpython-310.pyc
deleted file mode 100644
index 18fbb5c2d..000000000
Binary files a/gui/__pycache__/HandGestureInputControl.cpython-310.pyc and /dev/null differ
diff --git a/gui/__pycache__/MainMenu.cpython-310.pyc b/gui/__pycache__/MainMenu.cpython-310.pyc
deleted file mode 100644
index ce656755f..000000000
Binary files a/gui/__pycache__/MainMenu.cpython-310.pyc and /dev/null differ
diff --git a/gui/__pycache__/MainMenu.cpython-311.pyc b/gui/__pycache__/MainMenu.cpython-311.pyc
deleted file mode 100644
index 74ec77bf3..000000000
Binary files a/gui/__pycache__/MainMenu.cpython-311.pyc and /dev/null differ
diff --git a/gui/__pycache__/MiniGameSelectionScreen.cpython-310.pyc b/gui/__pycache__/MiniGameSelectionScreen.cpython-310.pyc
deleted file mode 100644
index 79407a415..000000000
Binary files a/gui/__pycache__/MiniGameSelectionScreen.cpython-310.pyc and /dev/null differ
diff --git a/gui/__pycache__/PlayerSelectionScreen.cpython-310.pyc b/gui/__pycache__/PlayerSelectionScreen.cpython-310.pyc
deleted file mode 100644
index 097168726..000000000
Binary files a/gui/__pycache__/PlayerSelectionScreen.cpython-310.pyc and /dev/null differ
diff --git a/gui/__pycache__/PlayerSelectionScreen.cpython-311.pyc b/gui/__pycache__/PlayerSelectionScreen.cpython-311.pyc
deleted file mode 100644
index 04280fe15..000000000
Binary files a/gui/__pycache__/PlayerSelectionScreen.cpython-311.pyc and /dev/null differ
diff --git a/gui/random.html b/gui/random.html
deleted file mode 100644
index 50c8f4f36..000000000
--- a/gui/random.html
+++ /dev/null
@@ -1,568 +0,0 @@
-
-
-
-
-Python: module random
-
-
-
- Random variable generators.
-
- bytes
- -----
- uniform bytes (values between 0 and 255)
-
- integers
- --------
- uniform within range
-
- sequences
- ---------
- pick random element
- pick random sample
- pick weighted random sample
- generate random permutation
-
- distributions on the real line:
- ------------------------------
- uniform
- triangular
- normal (Gaussian)
- lognormal
- negative exponential
- gamma
- beta
- pareto
- Weibull
-
- distributions on the circle (angles 0 to 2pi)
- ---------------------------------------------
- circular uniform
- von Mises
-
-General notes on the underlying Mersenne Twister core generator:
-
-* The period is 2**19937-1.
-* It is one of the most extensively tested generators in existence.
-* The random() method is implemented in C, executes in a single Python step,
- and is, therefore, threadsafe.
-
-
-
-
- Classes |
-
-| | |
-
-- _random.Random(builtins.object)
-
-
-
-- Random
-
-
-
-- SystemRandom
-
-
-
-
-
-
-
-
- class Random(_random.Random) |
-
-| |
-Random(x=None)
-
-Random number generator base class used by bound module functions.
-
-Used to instantiate instances of Random to get generators that don't
-share state.
-
-Class Random can also be subclassed if you want to use a different basic
-generator of your own devising: in that case, override the following
-methods: random(), seed(), getstate(), and setstate().
-Optionally, implement a getrandbits() method so that randrange()
-can cover arbitrarily large ranges. |
-| |
-- Method resolution order:
-- Random
-- _random.Random
-- builtins.object
-
-
-Methods defined here:
-- __getstate__(self)
- Helper for pickle.
-
-- __init__(self, x=None)
- Initialize an instance.
-
-Optional argument x controls seeding, as for Random.seed().
-
-- __reduce__(self)
- Helper for pickle.
-
-- __setstate__(self, state)
-
-- betavariate(self, alpha, beta)
- Beta distribution.
-
-Conditions on the parameters are alpha > 0 and beta > 0.
-Returned values range between 0 and 1.
-
-- choice(self, seq)
- Choose a random element from a non-empty sequence.
-
-- choices(self, population, weights=None, *, cum_weights=None, k=1)
- Return a k sized list of population elements chosen with replacement.
-
-If the relative weights or cumulative weights are not specified,
-the selections are made with equal probability.
-
-- expovariate(self, lambd)
- Exponential distribution.
-
-lambd is 1.0 divided by the desired mean. It should be
-nonzero. (The parameter would be called "lambda", but that is
-a reserved word in Python.) Returned values range from 0 to
-positive infinity if lambd is positive, and from negative
-infinity to 0 if lambd is negative.
-
-- gammavariate(self, alpha, beta)
- Gamma distribution. Not the gamma function!
-
-Conditions on the parameters are alpha > 0 and beta > 0.
-
-The probability distribution function is:
-
- x ** (alpha - 1) * math.exp(-x / beta)
- pdf(x) = --------------------------------------
- math.gamma(alpha) * beta ** alpha
-
-- gauss(self, mu=0.0, sigma=1.0)
- Gaussian distribution.
-
-mu is the mean, and sigma is the standard deviation. This is
-slightly faster than the normalvariate() function.
-
-Not thread-safe without a lock around calls.
-
-- getstate(self)
- Return internal state; can be passed to setstate() later.
-
-- lognormvariate(self, mu, sigma)
- Log normal distribution.
-
-If you take the natural logarithm of this distribution, you'll get a
-normal distribution with mean mu and standard deviation sigma.
-mu can have any value, and sigma must be greater than zero.
-
-- normalvariate(self, mu=0.0, sigma=1.0)
- Normal distribution.
-
-mu is the mean, and sigma is the standard deviation.
-
-- paretovariate(self, alpha)
- Pareto distribution. alpha is the shape parameter.
-
-- randbytes(self, n)
- Generate n random bytes.
-
-- randint(self, a, b)
- Return random integer in range [a, b], including both end points.
-
-- randrange(self, start, stop=None, step=1)
- Choose a random item from range(stop) or range(start, stop[, step]).
-
-Roughly equivalent to ``choice(range(start, stop, step))`` but
-supports arbitrarily large ranges and is optimized for common cases.
-
-- sample(self, population, k, *, counts=None)
- Chooses k unique random elements from a population sequence.
-
-Returns a new list containing elements from the population while
-leaving the original population unchanged. The resulting list is
-in selection order so that all sub-slices will also be valid random
-samples. This allows raffle winners (the sample) to be partitioned
-into grand prize and second place winners (the subslices).
-
-Members of the population need not be hashable or unique. If the
-population contains repeats, then each occurrence is a possible
-selection in the sample.
-
-Repeated elements can be specified one at a time or with the optional
-counts parameter. For example:
-
- sample(['red', 'blue'], counts=[4, 2], k=5)
-
-is equivalent to:
-
- sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)
-
-To choose a sample from a range of integers, use range() for the
-population argument. This is especially fast and space efficient
-for sampling from a large population:
-
- sample(range(10000000), 60)
-
-- seed(self, a=None, version=2)
- Initialize internal state from a seed.
-
-The only supported seed types are None, int, float,
-str, bytes, and bytearray.
-
-None or no argument seeds from current time or from an operating
-system specific randomness source if available.
-
-If *a* is an int, all bits are used.
-
-For version 2 (the default), all of the bits are used if *a* is a str,
-bytes, or bytearray. For version 1 (provided for reproducing random
-sequences from older versions of Python), the algorithm for str and
-bytes generates a narrower range of seeds.
-
-- setstate(self, state)
- Restore internal state from object returned by getstate().
-
-- shuffle(self, x)
- Shuffle list x in place, and return None.
-
-- triangular(self, low=0.0, high=1.0, mode=None)
- Triangular distribution.
-
-Continuous distribution bounded by given lower and upper limits,
-and having a given mode value in-between.
-
-http://en.wikipedia.org/wiki/Triangular_distribution
-
-- uniform(self, a, b)
- Get a random number in the range [a, b) or [a, b] depending on rounding.
-
-- vonmisesvariate(self, mu, kappa)
- Circular data distribution.
-
-mu is the mean angle, expressed in radians between 0 and 2*pi, and
-kappa is the concentration parameter, which must be greater than or
-equal to zero. If kappa is equal to zero, this distribution reduces
-to a uniform random angle over the range 0 to 2*pi.
-
-- weibullvariate(self, alpha, beta)
- Weibull distribution.
-
-alpha is the scale parameter and beta is the shape parameter.
-
-
-Class methods defined here:
-- __init_subclass__(**kwargs) from builtins.type
- Control how subclasses generate random integers.
-
-The algorithm a subclass can use depends on the random() and/or
-getrandbits() implementation available to it and determines
-whether it can generate random integers from arbitrarily large
-ranges.
-
-
-Data descriptors defined here:
-- __dict__
-- dictionary for instance variables (if defined)
-
-- __weakref__
-- list of weak references to the object (if defined)
-
-
-Data and other attributes defined here:
-- VERSION = 3
-
-
-Methods inherited from _random.Random:
-- getrandbits(self, k, /)
- getrandbits(k) -> x. Generates an int with k random bits.
-
-- random(self, /)
- random() -> x in the interval [0, 1).
-
-
-Static methods inherited from _random.Random:
-- __new__(*args, **kwargs) from builtins.type
- Create and return a new object. See help(type) for accurate signature.
-
- |
-
-
- class SystemRandom(Random) |
-
-| |
-SystemRandom(x=None)
-
-Alternate random number generator using sources provided
-by the operating system (such as /dev/urandom on Unix or
-CryptGenRandom on Windows).
-
- Not available on all systems (see os.urandom() for details). |
-| |
-- Method resolution order:
-- SystemRandom
-- Random
-- _random.Random
-- builtins.object
-
-
-Methods defined here:
-- getrandbits(self, k)
- getrandbits(k) -> x. Generates an int with k random bits.
-
-- getstate = _notimplemented(self, *args, **kwds)
-
-- randbytes(self, n)
- Generate n random bytes.
-
-- random(self)
- Get the next random number in the range 0.0 <= X < 1.0.
-
-- seed(self, *args, **kwds)
- Stub method. Not used for a system random number generator.
-
-- setstate = _notimplemented(self, *args, **kwds)
-
-
-Methods inherited from Random:
-- __getstate__(self)
- Helper for pickle.
-
-- __init__(self, x=None)
- Initialize an instance.
-
-Optional argument x controls seeding, as for Random.seed().
-
-- __reduce__(self)
- Helper for pickle.
-
-- __setstate__(self, state)
-
-- betavariate(self, alpha, beta)
- Beta distribution.
-
-Conditions on the parameters are alpha > 0 and beta > 0.
-Returned values range between 0 and 1.
-
-- choice(self, seq)
- Choose a random element from a non-empty sequence.
-
-- choices(self, population, weights=None, *, cum_weights=None, k=1)
- Return a k sized list of population elements chosen with replacement.
-
-If the relative weights or cumulative weights are not specified,
-the selections are made with equal probability.
-
-- expovariate(self, lambd)
- Exponential distribution.
-
-lambd is 1.0 divided by the desired mean. It should be
-nonzero. (The parameter would be called "lambda", but that is
-a reserved word in Python.) Returned values range from 0 to
-positive infinity if lambd is positive, and from negative
-infinity to 0 if lambd is negative.
-
-- gammavariate(self, alpha, beta)
- Gamma distribution. Not the gamma function!
-
-Conditions on the parameters are alpha > 0 and beta > 0.
-
-The probability distribution function is:
-
- x ** (alpha - 1) * math.exp(-x / beta)
- pdf(x) = --------------------------------------
- math.gamma(alpha) * beta ** alpha
-
-- gauss(self, mu=0.0, sigma=1.0)
- Gaussian distribution.
-
-mu is the mean, and sigma is the standard deviation. This is
-slightly faster than the normalvariate() function.
-
-Not thread-safe without a lock around calls.
-
-- lognormvariate(self, mu, sigma)
- Log normal distribution.
-
-If you take the natural logarithm of this distribution, you'll get a
-normal distribution with mean mu and standard deviation sigma.
-mu can have any value, and sigma must be greater than zero.
-
-- normalvariate(self, mu=0.0, sigma=1.0)
- Normal distribution.
-
-mu is the mean, and sigma is the standard deviation.
-
-- paretovariate(self, alpha)
- Pareto distribution. alpha is the shape parameter.
-
-- randint(self, a, b)
- Return random integer in range [a, b], including both end points.
-
-- randrange(self, start, stop=None, step=1)
- Choose a random item from range(stop) or range(start, stop[, step]).
-
-Roughly equivalent to ``choice(range(start, stop, step))`` but
-supports arbitrarily large ranges and is optimized for common cases.
-
-- sample(self, population, k, *, counts=None)
- Chooses k unique random elements from a population sequence.
-
-Returns a new list containing elements from the population while
-leaving the original population unchanged. The resulting list is
-in selection order so that all sub-slices will also be valid random
-samples. This allows raffle winners (the sample) to be partitioned
-into grand prize and second place winners (the subslices).
-
-Members of the population need not be hashable or unique. If the
-population contains repeats, then each occurrence is a possible
-selection in the sample.
-
-Repeated elements can be specified one at a time or with the optional
-counts parameter. For example:
-
- sample(['red', 'blue'], counts=[4, 2], k=5)
-
-is equivalent to:
-
- sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)
-
-To choose a sample from a range of integers, use range() for the
-population argument. This is especially fast and space efficient
-for sampling from a large population:
-
- sample(range(10000000), 60)
-
-- shuffle(self, x)
- Shuffle list x in place, and return None.
-
-- triangular(self, low=0.0, high=1.0, mode=None)
- Triangular distribution.
-
-Continuous distribution bounded by given lower and upper limits,
-and having a given mode value in-between.
-
-http://en.wikipedia.org/wiki/Triangular_distribution
-
-- uniform(self, a, b)
- Get a random number in the range [a, b) or [a, b] depending on rounding.
-
-- vonmisesvariate(self, mu, kappa)
- Circular data distribution.
-
-mu is the mean angle, expressed in radians between 0 and 2*pi, and
-kappa is the concentration parameter, which must be greater than or
-equal to zero. If kappa is equal to zero, this distribution reduces
-to a uniform random angle over the range 0 to 2*pi.
-
-- weibullvariate(self, alpha, beta)
- Weibull distribution.
-
-alpha is the scale parameter and beta is the shape parameter.
-
-
-Class methods inherited from Random:
-- __init_subclass__(**kwargs) from builtins.type
- Control how subclasses generate random integers.
-
-The algorithm a subclass can use depends on the random() and/or
-getrandbits() implementation available to it and determines
-whether it can generate random integers from arbitrarily large
-ranges.
-
-
-Data descriptors inherited from Random:
-- __dict__
-- dictionary for instance variables (if defined)
-
-- __weakref__
-- list of weak references to the object (if defined)
-
-
-Data and other attributes inherited from Random:
-- VERSION = 3
-
-
-Static methods inherited from _random.Random:
-- __new__(*args, **kwargs) from builtins.type
- Create and return a new object. See help(type) for accurate signature.
-
- | |
-
-
- Functions |
-
-| | |
-- betavariate(alpha, beta) method of Random instance
- Beta distribution.
-
-Conditions on the parameters are alpha > 0 and beta > 0.
-Returned values range between 0 and 1.
- - choice(seq) method of Random instance
- Choose a random element from a non-empty sequence.
- - choices(population, weights=None, *, cum_weights=None, k=1) method of Random instance
- Return a k sized list of population elements chosen with replacement.
-
-If the relative weights or cumulative weights are not specified,
-the selections are made with equal probability.
- - expovariate(lambd) method of Random instance
- Exponential distribution.
-
-lambd is 1.0 divided by the desired mean. It should be
-nonzero. (The parameter would be called "lambda", but that is
-a reserved word in Python.) Returned values range from 0 to
-positive infinity if lambd is positive, and from negative
-infinity to 0 if lambd is negative.
- - gammavariate(alpha, beta) method of Random instance
- Gamma distribution. Not the gamma function!
-
-Conditions on the parameters are alpha > 0 and beta > 0.
-
-The probability distribution function is:
-
- x ** (alpha - 1) * math.exp(-x / beta)
- pdf(x) = --------------------------------------
- math.gamma(alpha) * beta ** alpha
- - gauss(mu=0.0, sigma=1.0) method of Random instance
- Gaussian distribution.
-
-mu is the mean, and sigma is the standard deviation. This is
-slightly faster than the normalvariate() function.
-
-Not thread-safe without a lock around calls.
- - getrandbits(k, /) method of Random instance
- getrandbits(k) -> x. Generates an int with k random bits.
- - getstate() method of Random instance
- Return internal state; can be passed to setstate() later.
- - lognormvariate(mu, sigma) method of Random instance
- Log normal distribution.
-
-If you take the natural logarithm of this distribution, you'll get a
-normal distribution with mean mu and standard deviation sigma.
-mu can have any value, and sigma must be greater than zero.
- - normalvariate(mu=0.0, sigma=1.0) method of Random instance
- Normal distribution.
-
-mu is the mean, and sigma is the standard deviation.
- - paretovariate(alpha) method of Random instance
- Pareto distribution. alpha is the shape parameter.
- - randbytes(n) method of Random instance
- Generate n random bytes.
- - randint(a, b) method of Random instance
- Return random integer in range [a, b], including both end points.
- - random() method of Random instance
- random() -> x in the interval [0, 1).
- - randrange(start, stop=None, step=1) method of Random instance
- Choose a random item from range(stop) or range(start, stop[, step]).
-
-Roughly equivalent to ``choice(range(start, stop, step))`` but
-supports arbitrarily large ranges and is optimized for common cases.
- - sample(population, k, *, counts=None) method of Random instance
- Chooses k unique random elements from a population sequence.
-
-Returns a new list containing elements from the population while
-leaving the original population unchanged. The resulting list is
-in selection order so that all sub-slices will also be valid random
-samples. This allows raffle winners (the sample) to be partitioned
-into grand prize and second place winners (the subslices).
-
-Members of the population need not be hashable or unique. If the
-population contains repeats, then each occurrence is a possible
-selection in the sample.
-
-Repeated elements can be specified one at a time or with the optional
-counts parameter. For example:
-
- sample(['red', 'blue'], counts=[4, 2], k=5)
-
-is equivalent to:
-
- sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)
-
-To choose a sample from a range of integers, use range() for the
-population argument. This is especially fast and space efficient
-for sampling from a large population:
-
- sample(range(10000000), 60)
- - seed(a=None, version=2) method of Random instance
- Initialize internal state from a seed.
-
-The only supported seed types are None, int, float,
-str, bytes, and bytearray.
-
-None or no argument seeds from current time or from an operating
-system specific randomness source if available.
-
-If *a* is an int, all bits are used.
-
-For version 2 (the default), all of the bits are used if *a* is a str,
-bytes, or bytearray. For version 1 (provided for reproducing random
-sequences from older versions of Python), the algorithm for str and
-bytes generates a narrower range of seeds.
- - setstate(state) method of Random instance
- Restore internal state from object returned by getstate().
- - shuffle(x) method of Random instance
- Shuffle list x in place, and return None.
- - triangular(low=0.0, high=1.0, mode=None) method of Random instance
- Triangular distribution.
-
-Continuous distribution bounded by given lower and upper limits,
-and having a given mode value in-between.
-
-http://en.wikipedia.org/wiki/Triangular_distribution
- - uniform(a, b) method of Random instance
- Get a random number in the range [a, b) or [a, b] depending on rounding.
- - vonmisesvariate(mu, kappa) method of Random instance
- Circular data distribution.
-
-mu is the mean angle, expressed in radians between 0 and 2*pi, and
-kappa is the concentration parameter, which must be greater than or
-equal to zero. If kappa is equal to zero, this distribution reduces
-to a uniform random angle over the range 0 to 2*pi.
- - weibullvariate(alpha, beta) method of Random instance
- Weibull distribution.
-
-alpha is the scale parameter and beta is the shape parameter.
- |
-
-
- Data |
-
-| | |
-__all__ = ['Random', 'SystemRandom', 'betavariate', 'choice', 'choices', 'expovariate', 'gammavariate', 'gauss', 'getrandbits', 'getstate', 'lognormvariate', 'normalvariate', 'paretovariate', 'randbytes', 'randint', 'random', 'randrange', 'sample', 'seed', 'setstate', ...] |
-
\ No newline at end of file
diff --git a/pygame.html b/pygame.html
deleted file mode 100644
index 6aa49a6c6..000000000
--- a/pygame.html
+++ /dev/null
@@ -1,43 +0,0 @@
-
-Python: class pygame
-
-
-
-
-
-
-class pygame(builtins.object) |
-
-| |
-The pygame class is where the mini-game(s) is initialized, launched/run, and terminated.
-Each component of the class is designed to operate via their respecitve functions.
-
-Attributes:
-None
-
-Methods:
-init(): void
-startGameLoop(): void
-quit(): void |
-| |
-Methods defined here:
-- init()
- The respective pygame mini-game(s) is initialized, and the method is void returning no value.
-
-- quit()
- This ends or terminates the game bringing the user back to the GUI or menu screen, and the method is void returning no value.
-Pre-condition: startGameLoop() is actively running.
-Post-condition: brings user back to menu screen.
-
-- startGameLoop()
- Launches/runs the specified pygame mini-game, and the method is void returning no value.
-Pre-condition: init() has been called to initalize the game state.
-Post-condition: The game is currently being run.
-
-
-Data descriptors defined here:
-- __dict__
-- dictionary for instance variables (if defined)
-
-- __weakref__
-- list of weak references to the object (if defined)
-
- |
-
\ No newline at end of file
diff --git a/pygame_class.py b/pygame_class.py
deleted file mode 100644
index bf67f5bb6..000000000
--- a/pygame_class.py
+++ /dev/null
@@ -1,40 +0,0 @@
-import pygame_class
-import pydoc
-
-class pygame_class:
- """
- The pygame class is where the mini-game(s) is initialized, launched/run, and terminated.
- Each component of the class is designed to operate via their respecitve functions.
-
- Attributes:
- None
-
- Methods:
- init(): void
- startGameLoop(): void
- quit(): void
- """
-
- def init():
- """
- The respective pygame mini-game(s) is initialized, and the method is void returning no value.
- """
- return
-
- def startGameLoop():
- """
- Launches/runs the specified pygame mini-game, and the method is void returning no value.
- Pre-condition: init() has been called to initalize the game state.
- Post-condition: The game is currently being run.
- """
- return
-
- def quit():
- """
- This ends or terminates the game bringing the user back to the GUI or menu screen, and the method is void returning no value.
- Pre-condition: startGameLoop() is actively running.
- Post-condition: brings user back to menu screen.
- """
- return
-
-pydoc.writedoc("pygame_class.py")
\ No newline at end of file
diff --git a/random.html b/random.html
deleted file mode 100644
index 50c8f4f36..000000000
--- a/random.html
+++ /dev/null
@@ -1,568 +0,0 @@
-
-
-
-
-Python: module random
-
-
-
- Random variable generators.
-
- bytes
- -----
- uniform bytes (values between 0 and 255)
-
- integers
- --------
- uniform within range
-
- sequences
- ---------
- pick random element
- pick random sample
- pick weighted random sample
- generate random permutation
-
- distributions on the real line:
- ------------------------------
- uniform
- triangular
- normal (Gaussian)
- lognormal
- negative exponential
- gamma
- beta
- pareto
- Weibull
-
- distributions on the circle (angles 0 to 2pi)
- ---------------------------------------------
- circular uniform
- von Mises
-
-General notes on the underlying Mersenne Twister core generator:
-
-* The period is 2**19937-1.
-* It is one of the most extensively tested generators in existence.
-* The random() method is implemented in C, executes in a single Python step,
- and is, therefore, threadsafe.
-
-
-
-
- Classes |
-
-| | |
-
-- _random.Random(builtins.object)
-
-
-
-- Random
-
-
-
-- SystemRandom
-
-
-
-
-
-
-
-
- class Random(_random.Random) |
-
-| |
-Random(x=None)
-
-Random number generator base class used by bound module functions.
-
-Used to instantiate instances of Random to get generators that don't
-share state.
-
-Class Random can also be subclassed if you want to use a different basic
-generator of your own devising: in that case, override the following
-methods: random(), seed(), getstate(), and setstate().
-Optionally, implement a getrandbits() method so that randrange()
-can cover arbitrarily large ranges. |
-| |
-- Method resolution order:
-- Random
-- _random.Random
-- builtins.object
-
-
-Methods defined here:
-- __getstate__(self)
- Helper for pickle.
-
-- __init__(self, x=None)
- Initialize an instance.
-
-Optional argument x controls seeding, as for Random.seed().
-
-- __reduce__(self)
- Helper for pickle.
-
-- __setstate__(self, state)
-
-- betavariate(self, alpha, beta)
- Beta distribution.
-
-Conditions on the parameters are alpha > 0 and beta > 0.
-Returned values range between 0 and 1.
-
-- choice(self, seq)
- Choose a random element from a non-empty sequence.
-
-- choices(self, population, weights=None, *, cum_weights=None, k=1)
- Return a k sized list of population elements chosen with replacement.
-
-If the relative weights or cumulative weights are not specified,
-the selections are made with equal probability.
-
-- expovariate(self, lambd)
- Exponential distribution.
-
-lambd is 1.0 divided by the desired mean. It should be
-nonzero. (The parameter would be called "lambda", but that is
-a reserved word in Python.) Returned values range from 0 to
-positive infinity if lambd is positive, and from negative
-infinity to 0 if lambd is negative.
-
-- gammavariate(self, alpha, beta)
- Gamma distribution. Not the gamma function!
-
-Conditions on the parameters are alpha > 0 and beta > 0.
-
-The probability distribution function is:
-
- x ** (alpha - 1) * math.exp(-x / beta)
- pdf(x) = --------------------------------------
- math.gamma(alpha) * beta ** alpha
-
-- gauss(self, mu=0.0, sigma=1.0)
- Gaussian distribution.
-
-mu is the mean, and sigma is the standard deviation. This is
-slightly faster than the normalvariate() function.
-
-Not thread-safe without a lock around calls.
-
-- getstate(self)
- Return internal state; can be passed to setstate() later.
-
-- lognormvariate(self, mu, sigma)
- Log normal distribution.
-
-If you take the natural logarithm of this distribution, you'll get a
-normal distribution with mean mu and standard deviation sigma.
-mu can have any value, and sigma must be greater than zero.
-
-- normalvariate(self, mu=0.0, sigma=1.0)
- Normal distribution.
-
-mu is the mean, and sigma is the standard deviation.
-
-- paretovariate(self, alpha)
- Pareto distribution. alpha is the shape parameter.
-
-- randbytes(self, n)
- Generate n random bytes.
-
-- randint(self, a, b)
- Return random integer in range [a, b], including both end points.
-
-- randrange(self, start, stop=None, step=1)
- Choose a random item from range(stop) or range(start, stop[, step]).
-
-Roughly equivalent to ``choice(range(start, stop, step))`` but
-supports arbitrarily large ranges and is optimized for common cases.
-
-- sample(self, population, k, *, counts=None)
- Chooses k unique random elements from a population sequence.
-
-Returns a new list containing elements from the population while
-leaving the original population unchanged. The resulting list is
-in selection order so that all sub-slices will also be valid random
-samples. This allows raffle winners (the sample) to be partitioned
-into grand prize and second place winners (the subslices).
-
-Members of the population need not be hashable or unique. If the
-population contains repeats, then each occurrence is a possible
-selection in the sample.
-
-Repeated elements can be specified one at a time or with the optional
-counts parameter. For example:
-
- sample(['red', 'blue'], counts=[4, 2], k=5)
-
-is equivalent to:
-
- sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)
-
-To choose a sample from a range of integers, use range() for the
-population argument. This is especially fast and space efficient
-for sampling from a large population:
-
- sample(range(10000000), 60)
-
-- seed(self, a=None, version=2)
- Initialize internal state from a seed.
-
-The only supported seed types are None, int, float,
-str, bytes, and bytearray.
-
-None or no argument seeds from current time or from an operating
-system specific randomness source if available.
-
-If *a* is an int, all bits are used.
-
-For version 2 (the default), all of the bits are used if *a* is a str,
-bytes, or bytearray. For version 1 (provided for reproducing random
-sequences from older versions of Python), the algorithm for str and
-bytes generates a narrower range of seeds.
-
-- setstate(self, state)
- Restore internal state from object returned by getstate().
-
-- shuffle(self, x)
- Shuffle list x in place, and return None.
-
-- triangular(self, low=0.0, high=1.0, mode=None)
- Triangular distribution.
-
-Continuous distribution bounded by given lower and upper limits,
-and having a given mode value in-between.
-
-http://en.wikipedia.org/wiki/Triangular_distribution
-
-- uniform(self, a, b)
- Get a random number in the range [a, b) or [a, b] depending on rounding.
-
-- vonmisesvariate(self, mu, kappa)
- Circular data distribution.
-
-mu is the mean angle, expressed in radians between 0 and 2*pi, and
-kappa is the concentration parameter, which must be greater than or
-equal to zero. If kappa is equal to zero, this distribution reduces
-to a uniform random angle over the range 0 to 2*pi.
-
-- weibullvariate(self, alpha, beta)
- Weibull distribution.
-
-alpha is the scale parameter and beta is the shape parameter.
-
-
-Class methods defined here:
-- __init_subclass__(**kwargs) from builtins.type
- Control how subclasses generate random integers.
-
-The algorithm a subclass can use depends on the random() and/or
-getrandbits() implementation available to it and determines
-whether it can generate random integers from arbitrarily large
-ranges.
-
-
-Data descriptors defined here:
-- __dict__
-- dictionary for instance variables (if defined)
-
-- __weakref__
-- list of weak references to the object (if defined)
-
-
-Data and other attributes defined here:
-- VERSION = 3
-
-
-Methods inherited from _random.Random:
-- getrandbits(self, k, /)
- getrandbits(k) -> x. Generates an int with k random bits.
-
-- random(self, /)
- random() -> x in the interval [0, 1).
-
-
-Static methods inherited from _random.Random:
-- __new__(*args, **kwargs) from builtins.type
- Create and return a new object. See help(type) for accurate signature.
-
- |
-
-
- class SystemRandom(Random) |
-
-| |
-SystemRandom(x=None)
-
-Alternate random number generator using sources provided
-by the operating system (such as /dev/urandom on Unix or
-CryptGenRandom on Windows).
-
- Not available on all systems (see os.urandom() for details). |
-| |
-- Method resolution order:
-- SystemRandom
-- Random
-- _random.Random
-- builtins.object
-
-
-Methods defined here:
-- getrandbits(self, k)
- getrandbits(k) -> x. Generates an int with k random bits.
-
-- getstate = _notimplemented(self, *args, **kwds)
-
-- randbytes(self, n)
- Generate n random bytes.
-
-- random(self)
- Get the next random number in the range 0.0 <= X < 1.0.
-
-- seed(self, *args, **kwds)
- Stub method. Not used for a system random number generator.
-
-- setstate = _notimplemented(self, *args, **kwds)
-
-
-Methods inherited from Random:
-- __getstate__(self)
- Helper for pickle.
-
-- __init__(self, x=None)
- Initialize an instance.
-
-Optional argument x controls seeding, as for Random.seed().
-
-- __reduce__(self)
- Helper for pickle.
-
-- __setstate__(self, state)
-
-- betavariate(self, alpha, beta)
- Beta distribution.
-
-Conditions on the parameters are alpha > 0 and beta > 0.
-Returned values range between 0 and 1.
-
-- choice(self, seq)
- Choose a random element from a non-empty sequence.
-
-- choices(self, population, weights=None, *, cum_weights=None, k=1)
- Return a k sized list of population elements chosen with replacement.
-
-If the relative weights or cumulative weights are not specified,
-the selections are made with equal probability.
-
-- expovariate(self, lambd)
- Exponential distribution.
-
-lambd is 1.0 divided by the desired mean. It should be
-nonzero. (The parameter would be called "lambda", but that is
-a reserved word in Python.) Returned values range from 0 to
-positive infinity if lambd is positive, and from negative
-infinity to 0 if lambd is negative.
-
-- gammavariate(self, alpha, beta)
- Gamma distribution. Not the gamma function!
-
-Conditions on the parameters are alpha > 0 and beta > 0.
-
-The probability distribution function is:
-
- x ** (alpha - 1) * math.exp(-x / beta)
- pdf(x) = --------------------------------------
- math.gamma(alpha) * beta ** alpha
-
-- gauss(self, mu=0.0, sigma=1.0)
- Gaussian distribution.
-
-mu is the mean, and sigma is the standard deviation. This is
-slightly faster than the normalvariate() function.
-
-Not thread-safe without a lock around calls.
-
-- lognormvariate(self, mu, sigma)
- Log normal distribution.
-
-If you take the natural logarithm of this distribution, you'll get a
-normal distribution with mean mu and standard deviation sigma.
-mu can have any value, and sigma must be greater than zero.
-
-- normalvariate(self, mu=0.0, sigma=1.0)
- Normal distribution.
-
-mu is the mean, and sigma is the standard deviation.
-
-- paretovariate(self, alpha)
- Pareto distribution. alpha is the shape parameter.
-
-- randint(self, a, b)
- Return random integer in range [a, b], including both end points.
-
-- randrange(self, start, stop=None, step=1)
- Choose a random item from range(stop) or range(start, stop[, step]).
-
-Roughly equivalent to ``choice(range(start, stop, step))`` but
-supports arbitrarily large ranges and is optimized for common cases.
-
-- sample(self, population, k, *, counts=None)
- Chooses k unique random elements from a population sequence.
-
-Returns a new list containing elements from the population while
-leaving the original population unchanged. The resulting list is
-in selection order so that all sub-slices will also be valid random
-samples. This allows raffle winners (the sample) to be partitioned
-into grand prize and second place winners (the subslices).
-
-Members of the population need not be hashable or unique. If the
-population contains repeats, then each occurrence is a possible
-selection in the sample.
-
-Repeated elements can be specified one at a time or with the optional
-counts parameter. For example:
-
- sample(['red', 'blue'], counts=[4, 2], k=5)
-
-is equivalent to:
-
- sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)
-
-To choose a sample from a range of integers, use range() for the
-population argument. This is especially fast and space efficient
-for sampling from a large population:
-
- sample(range(10000000), 60)
-
-- shuffle(self, x)
- Shuffle list x in place, and return None.
-
-- triangular(self, low=0.0, high=1.0, mode=None)
- Triangular distribution.
-
-Continuous distribution bounded by given lower and upper limits,
-and having a given mode value in-between.
-
-http://en.wikipedia.org/wiki/Triangular_distribution
-
-- uniform(self, a, b)
- Get a random number in the range [a, b) or [a, b] depending on rounding.
-
-- vonmisesvariate(self, mu, kappa)
- Circular data distribution.
-
-mu is the mean angle, expressed in radians between 0 and 2*pi, and
-kappa is the concentration parameter, which must be greater than or
-equal to zero. If kappa is equal to zero, this distribution reduces
-to a uniform random angle over the range 0 to 2*pi.
-
-- weibullvariate(self, alpha, beta)
- Weibull distribution.
-
-alpha is the scale parameter and beta is the shape parameter.
-
-
-Class methods inherited from Random:
-- __init_subclass__(**kwargs) from builtins.type
- Control how subclasses generate random integers.
-
-The algorithm a subclass can use depends on the random() and/or
-getrandbits() implementation available to it and determines
-whether it can generate random integers from arbitrarily large
-ranges.
-
-
-Data descriptors inherited from Random:
-- __dict__
-- dictionary for instance variables (if defined)
-
-- __weakref__
-- list of weak references to the object (if defined)
-
-
-Data and other attributes inherited from Random:
-- VERSION = 3
-
-
-Static methods inherited from _random.Random:
-- __new__(*args, **kwargs) from builtins.type
- Create and return a new object. See help(type) for accurate signature.
-
- | |
-
-
- Functions |
-
-| | |
-- betavariate(alpha, beta) method of Random instance
- Beta distribution.
-
-Conditions on the parameters are alpha > 0 and beta > 0.
-Returned values range between 0 and 1.
- - choice(seq) method of Random instance
- Choose a random element from a non-empty sequence.
- - choices(population, weights=None, *, cum_weights=None, k=1) method of Random instance
- Return a k sized list of population elements chosen with replacement.
-
-If the relative weights or cumulative weights are not specified,
-the selections are made with equal probability.
- - expovariate(lambd) method of Random instance
- Exponential distribution.
-
-lambd is 1.0 divided by the desired mean. It should be
-nonzero. (The parameter would be called "lambda", but that is
-a reserved word in Python.) Returned values range from 0 to
-positive infinity if lambd is positive, and from negative
-infinity to 0 if lambd is negative.
- - gammavariate(alpha, beta) method of Random instance
- Gamma distribution. Not the gamma function!
-
-Conditions on the parameters are alpha > 0 and beta > 0.
-
-The probability distribution function is:
-
- x ** (alpha - 1) * math.exp(-x / beta)
- pdf(x) = --------------------------------------
- math.gamma(alpha) * beta ** alpha
- - gauss(mu=0.0, sigma=1.0) method of Random instance
- Gaussian distribution.
-
-mu is the mean, and sigma is the standard deviation. This is
-slightly faster than the normalvariate() function.
-
-Not thread-safe without a lock around calls.
- - getrandbits(k, /) method of Random instance
- getrandbits(k) -> x. Generates an int with k random bits.
- - getstate() method of Random instance
- Return internal state; can be passed to setstate() later.
- - lognormvariate(mu, sigma) method of Random instance
- Log normal distribution.
-
-If you take the natural logarithm of this distribution, you'll get a
-normal distribution with mean mu and standard deviation sigma.
-mu can have any value, and sigma must be greater than zero.
- - normalvariate(mu=0.0, sigma=1.0) method of Random instance
- Normal distribution.
-
-mu is the mean, and sigma is the standard deviation.
- - paretovariate(alpha) method of Random instance
- Pareto distribution. alpha is the shape parameter.
- - randbytes(n) method of Random instance
- Generate n random bytes.
- - randint(a, b) method of Random instance
- Return random integer in range [a, b], including both end points.
- - random() method of Random instance
- random() -> x in the interval [0, 1).
- - randrange(start, stop=None, step=1) method of Random instance
- Choose a random item from range(stop) or range(start, stop[, step]).
-
-Roughly equivalent to ``choice(range(start, stop, step))`` but
-supports arbitrarily large ranges and is optimized for common cases.
- - sample(population, k, *, counts=None) method of Random instance
- Chooses k unique random elements from a population sequence.
-
-Returns a new list containing elements from the population while
-leaving the original population unchanged. The resulting list is
-in selection order so that all sub-slices will also be valid random
-samples. This allows raffle winners (the sample) to be partitioned
-into grand prize and second place winners (the subslices).
-
-Members of the population need not be hashable or unique. If the
-population contains repeats, then each occurrence is a possible
-selection in the sample.
-
-Repeated elements can be specified one at a time or with the optional
-counts parameter. For example:
-
- sample(['red', 'blue'], counts=[4, 2], k=5)
-
-is equivalent to:
-
- sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)
-
-To choose a sample from a range of integers, use range() for the
-population argument. This is especially fast and space efficient
-for sampling from a large population:
-
- sample(range(10000000), 60)
- - seed(a=None, version=2) method of Random instance
- Initialize internal state from a seed.
-
-The only supported seed types are None, int, float,
-str, bytes, and bytearray.
-
-None or no argument seeds from current time or from an operating
-system specific randomness source if available.
-
-If *a* is an int, all bits are used.
-
-For version 2 (the default), all of the bits are used if *a* is a str,
-bytes, or bytearray. For version 1 (provided for reproducing random
-sequences from older versions of Python), the algorithm for str and
-bytes generates a narrower range of seeds.
- - setstate(state) method of Random instance
- Restore internal state from object returned by getstate().
- - shuffle(x) method of Random instance
- Shuffle list x in place, and return None.
- - triangular(low=0.0, high=1.0, mode=None) method of Random instance
- Triangular distribution.
-
-Continuous distribution bounded by given lower and upper limits,
-and having a given mode value in-between.
-
-http://en.wikipedia.org/wiki/Triangular_distribution
- - uniform(a, b) method of Random instance
- Get a random number in the range [a, b) or [a, b] depending on rounding.
- - vonmisesvariate(mu, kappa) method of Random instance
- Circular data distribution.
-
-mu is the mean angle, expressed in radians between 0 and 2*pi, and
-kappa is the concentration parameter, which must be greater than or
-equal to zero. If kappa is equal to zero, this distribution reduces
-to a uniform random angle over the range 0 to 2*pi.
- - weibullvariate(alpha, beta) method of Random instance
- Weibull distribution.
-
-alpha is the scale parameter and beta is the shape parameter.
- |
-
-
- Data |
-
-| | |
-__all__ = ['Random', 'SystemRandom', 'betavariate', 'choice', 'choices', 'expovariate', 'gammavariate', 'gauss', 'getrandbits', 'getstate', 'lognormvariate', 'normalvariate', 'paretovariate', 'randbytes', 'randint', 'random', 'randrange', 'sample', 'seed', 'setstate', ...] |
-
\ No newline at end of file
diff --git a/source/gesture inference/Console.py b/source/gesture inference/Console.py
index 1a152a307..e6c3ee992 100644
--- a/source/gesture inference/Console.py
+++ b/source/gesture inference/Console.py
@@ -3,8 +3,11 @@
from rich.layout import Layout
from rich.console import Console
from rich.panel import Panel
+from rich.columns import Columns
+
import os
+
class GestureConsole:
# make this class a singleton
_initialized = False
@@ -14,7 +17,7 @@ def __new__(cls):
cls.instance = super(GestureConsole, cls).__new__(cls)
return cls.instance
- def __init__(self) -> None:
+ def __init__(self, max_tables=5) -> None:
if not self._initialized:
self._initialized = True
self.console = ConsolePanel()
@@ -22,29 +25,43 @@ def __init__(self) -> None:
self.layout.split_column(Layout(name="upper"), Layout(name="lower"))
self.live = Live(self.layout, auto_refresh=False)
self.live.start()
+ self.tables = []
+ for i in range(max_tables):
+ self.tables.append(Table())
+
+ def table(self, headers, rows, table_number=0):
+ table = self.tables[table_number]
+ table.columns.clear() # Clear existing columns
+ table.rows.clear() # Clear existing rows
- def table(self, headers, rows):
- table = Table()
for header in headers:
table.add_column(header)
for row in rows:
table_row = []
for item in row:
- table_row.append(str(f"{float(item):.3f}"))
- table.add_row(*table_row)
+ if isinstance(item, float):
+ table_row.append(str(f"{float(item):.3f}"))
+ else:
+ table_row.append(str(item))
+ table.add_row(*table_row)
- self.layout["upper"].update(Panel(table))
- self.update()
+ self.layout["upper"].update(
+ Panel.fit(
+ Columns(self.tables),
+ )
+ )
+ self.update()
def print(self, string: str):
self.console.print(string)
self.layout["lower"].update(Panel(self.console))
self.update()
-
+
def update(self):
self.live.update(self.layout, refresh=True)
+
# https://stackoverflow.com/questions/71077706/redirect-print-and-or-logging-to-panel
class ConsolePanel(Console):
def __init__(self, *args, **kwargs):
diff --git a/source/gesture inference/GetHands.py b/source/gesture inference/GetHands.py
index 6aafacdaf..99e7a7813 100644
--- a/source/gesture inference/GetHands.py
+++ b/source/gesture inference/GetHands.py
@@ -14,6 +14,7 @@
dname = os.path.dirname(abspath)
os.chdir(dname)
+
class GetHands(Thread):
"""
Class that continuously gets frames and extracts hand data
@@ -22,41 +23,42 @@ class GetHands(Thread):
def __init__(
self,
- render_hands,
mediapipe_model="hand_landmarker.task",
- gesture_model = "simple.pth",
- control_mouse=None,
flags=None,
- keyboard=None,
- click_sensitinity=0.05,
):
- Thread.__init__(self)
+ Thread.__init__(self)
self.model_path = mediapipe_model
- self.render_hands = render_hands
self.confidence = 0.5
self.stopped = False
- self.control_mouse = control_mouse
self.flags = flags
- self.click_sensitinity = click_sensitinity
- self.keyboard = keyboard
self.console = GestureConsole()
self.camera = Webcam()
- self.gesture_model = NeuralNet(gesture_model)
+ self.set_gesture_model(flags["gesture_model_path"])
+
self.gesture_list = self.gesture_model.labels
self.confidence_vectors = self.gesture_model.confidence_vector
- self.gestures = ['no gesture']
+ self.gestures = ["no gesture"]
self.delay = 0
+ self.result = None
+
+ self.click = ""
+ self.location = []
+ self.velocity = []
+ self.num_hands_deteced = 0
(self.grabbed, self.frame) = self.camera.read()
self.timer = 0
- self.build_model(flags["number_of_hands"])
+ self.build_mediapipe_model(flags["number_of_hands"])
+
+ def set_gesture_model(self, path):
+ self.gesture_model = NeuralNet(path)
- def build_model(self, hands_num):
+ def build_mediapipe_model(self, hands_num):
"""Takes in option parameters for the Mediapipe hands model
Args:
@@ -80,22 +82,6 @@ def build_model(self, hands_num):
# build hands model
self.hands_detector = self.HandLandmarker.create_from_options(self.options)
- def move_mouse(self, location, button: str):
- """Wrapper method to control the mouse
-
- Args:
- hands_location_on_screen (origins): The origins result from find_velocity_and_location()
- mouse_button_text (str): Type of click
- """
- if callable(self.control_mouse):
- if location != []:
- # (0,0) is the top left corner
- self.control_mouse(
- location[0][0],
- location[0][1],
- button,
- )
-
def results_callback(
self,
result: mp.tasks.vision.HandLandmarkerResult,
@@ -105,16 +91,21 @@ def results_callback(
# this try catch block is for debugging. this code runs in a different thread and doesn't automatically raise its own exceptions
try:
- if len(result.hand_world_landmarks) == 0:
- self.render_hands(
- result,
- None,
- None,
- None,
- )
+ self.location = []
+ self.click = ""
+ self.velocity = []
+ self.num_hands_deteced = len(result.hand_world_landmarks)
+ if self.num_hands_deteced == 0:
+ self.result = []
+ self.confidence_vectors=[]
+ self.console.table(self.gesture_list, self.confidence_vectors) #clear table
return
+ self.result = result
+
location, velocity = self.gesture_model.find_velocity_and_location(result)
+ self.location = location
+ self.velocity = velocity
if self.flags["run_model_flag"]:
@@ -128,29 +119,20 @@ def results_callback(
# self.keyboard.gesture_input(self.confidence_vector[0])
# serialized input
- hand_confidences = [] #prepare data for console table
- gestures = [] #store gesture output as text
+ hand_confidences = [] # prepare data for console table
+ gestures = [] # store gesture output as text
for index, hand in enumerate(model_inputs):
confidences, predicted, predicted_confidence = (
self.gesture_model.get_gesture([hand], print_table=False)
- )
- gestures.append(self.gesture_list[predicted[0]]) # save gesture
+ )
+ gestures.append(self.gesture_list[predicted[0]]) # save gesture
hand_confidences.append(confidences[0])
# only take inputs from the first hand, subsequent hands can't control the keyboard
self.gestures = gestures
self.confidence_vectors = hand_confidences
- self.keyboard.gesture_input(self.confidence_vectors[0])
-
- self.console.table(self.gesture_list, hand_confidences)
-
- if self.flags["move_mouse_flag"] and location != []:
- mouse_button_text = ""
- hand = result.hand_world_landmarks[0]
- if self.is_clicking(hand[8], hand[4]):
- mouse_button_text = "left"
- self.move_mouse(location, mouse_button_text)
+ self.console.table(self.gesture_list, self.confidence_vectors)
# timestamps are in microseconds so convert to ms
@@ -158,26 +140,10 @@ def results_callback(
self.delay = (current_time - self.timer) * 1000
self.timer = current_time
- self.render_hands(
- result,
- self.flags["render_hands_mode"],
- location,
- velocity,
- )
-
except Exception as e:
traceback.print_exc()
quit()
- def is_clicking(self, tip1, tip2):
- distance = math.sqrt(
- (tip1.x - tip2.x) ** 2 + (tip1.y - tip2.y) ** 2 + (tip1.z - tip2.z) ** 2
- )
- if distance < self.click_sensitinity:
- return True
- else:
- return False
-
def run(self):
"""Continuously grabs new frames from the webcam and uses Mediapipe to detect hands"""
while not self.stopped:
@@ -186,7 +152,6 @@ def run(self):
self.stop()
else:
(self.grabbed, self.frame) = self.camera.read()
-
# Detect hand landmarks
self.detect_hands(self.frame)
diff --git a/source/gesture inference/Keyboard.py b/source/gesture inference/Keyboard.py
index 64227798e..6a5cd7b61 100644
--- a/source/gesture inference/Keyboard.py
+++ b/source/gesture inference/Keyboard.py
@@ -1,10 +1,18 @@
-import pyautogui
+import pydirectinput
import time
from Console import GestureConsole
import numpy as np
+
+
class Keyboard:
def __init__(
- self, threshold=0.0, toggle_key_threshold=0.15, toggle_key_toggle_time=1, toggle_mouse_func=None, console=None
+ self,
+ threshold=0.0,
+ toggle_key_threshold=0.15,
+ toggle_key_toggle_time=1,
+ toggle_mouse_func=None,
+ flags=None,
+ toggle_key="",
) -> None:
"""_summary_
@@ -16,21 +24,29 @@ def __init__(
Key press options:
['\t', '\n', '\r', ' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 'accept', 'add', 'alt', 'altleft', 'altright', 'apps', 'backspace', 'browserback', 'browserfavorites', 'browserforward', 'browserhome', 'browserrefresh', 'browsersearch', 'browserstop', 'capslock', 'clear', 'convert', 'ctrl', 'ctrlleft', 'ctrlright', 'decimal', 'del', 'delete', 'divide', 'down', 'end', 'enter', 'esc', 'escape', 'execute', 'f1', 'f10', 'f11', 'f12', 'f13', 'f14', 'f15', 'f16', 'f17', 'f18', 'f19', 'f2', 'f20', 'f21', 'f22', 'f23', 'f24', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'final', 'fn', 'hanguel', 'hangul', 'hanja', 'help', 'home', 'insert', 'junja', 'kana', 'kanji', 'launchapp1', 'launchapp2', 'launchmail', 'launchmediaselect', 'left', 'modechange', 'multiply', 'nexttrack', 'nonconvert', 'num0', 'num1', 'num2', 'num3', 'num4', 'num5', 'num6', 'num7', 'num8', 'num9', 'numlock', 'pagedown', 'pageup', 'pause', 'pgdn', 'pgup', 'playpause', 'prevtrack', 'print', 'printscreen', 'prntscrn', 'prtsc', 'prtscr', 'return', 'right', 'scrolllock', 'select', 'separator', 'shift', 'shiftleft', 'shiftright', 'sleep', 'space', 'stop', 'subtract', 'tab', 'up', 'volumedown', 'volumemute', 'volumeup', 'win', 'winleft', 'winright', 'yen', 'command', 'option', 'optionleft', 'optionright']
"""
- pyautogui.FAILSAFE = False
- pyautogui.PAUSE = 0
+ pydirectinput.FAILSAFE = False
+ pydirectinput.PAUSE = 0
self.threshold = threshold
self.toggle_key_threshold = toggle_key_threshold
self.last_time = time.time()
self.last_time_toggle_key = time.time()
self.last_key = ""
self.toggle_key_pressed = False
- self.key_presed = False
+ self.key_pressed = False
self.toggle_mouse_func = toggle_mouse_func
self.toggle_key_toggle_time = toggle_key_toggle_time
self.console = GestureConsole()
+ self.flags = flags
+ self.toggle_key = toggle_key
- def gesture_input(self, confidences):
+ def release(self):
+ if self.key_pressed:
+ pydirectinput.keyUp(self.last_key)
+ self.key_pressed = False
+ if self.toggle_key_pressed:
+ self.toggle_key_pressed = False
+ def gesture_input(self, confidences):
max_value = np.max(confidences)
max_index = np.argmax(confidences)
if max_index == 0:
@@ -38,35 +54,41 @@ def gesture_input(self, confidences):
elif max_index == 1:
self.press("none")
elif max_index == 2:
- self.press("toggle")
+ self.press(self.toggle_key)
def press(self, key: str):
- current_time = time.time() # if it has been longer than threshold time
-
- # if its a new key set state to not pressed
+
+ current_time = time.time()
+ if key == "none":
+ self.key_pressed = False
+ pydirectinput.keyUp(self.last_key) # Release the last key
+ return
if key != self.last_key:
- self.key_presed = False
+ self.key_pressed = False
self.toggle_key_pressed = False
self.last_key = key
- # start timers
- if key == "none":
- return
- if key == "toggle":
+
+ if key == self.toggle_key:
self.last_time_toggle_key = current_time
else:
self.last_time = current_time
- # if the toggle key has been requested for longer than the threashold
- if key == "toggle":
- if not self.toggle_key_pressed or current_time - self.last_time_toggle_key > self.toggle_key_toggle_time:
- if current_time - self.last_time_toggle_key > self.toggle_key_threshold:
- if self.toggle_mouse_func != None:
- self.toggle_mouse_func()
- self.toggle_key_pressed = True
- self.last_time_toggle_key = current_time
-
- # if the non toggle key has been requested for longer than the normal threashold
- elif current_time - self.last_time > self.threshold and self.key_presed == False:
- self.key_presed = True
- self.console.print(f"pressing key: {key}")
- pyautogui.press(key, _pause=False)
+ if key == self.toggle_key:
+ self.handle_toggle_key(current_time)
+ elif current_time - self.last_time > self.threshold and not self.key_pressed:
+ self.key_pressed = True
+ #self.console.print(f"pressing key: {key}")
+ pydirectinput.keyDown(key)
+ # else:
+ # self.console.print(f"key {key} already pressed")
+
+ def handle_toggle_key(self, current_time):
+ if (
+ not self.toggle_key_pressed
+ or current_time - self.last_time_toggle_key > self.toggle_key_toggle_time
+ ):
+ if current_time - self.last_time_toggle_key > self.toggle_key_threshold:
+ if self.toggle_mouse_func is not None:
+ self.toggle_mouse_func()
+ self.toggle_key_pressed = True
+ self.last_time_toggle_key = current_time
diff --git a/source/gesture inference/Mouse.py b/source/gesture inference/Mouse.py
index d07b41be6..36313241c 100644
--- a/source/gesture inference/Mouse.py
+++ b/source/gesture inference/Mouse.py
@@ -1,20 +1,43 @@
import pyautogui
import time
from Console import GestureConsole
+import math
+
+
class Mouse:
def __init__(
- self, mouse_scale, click_threshold_time=0.2, drag_threshold_time=0.15, console=None
+ self,
+ mouse_sensitivity=1,
+ click_threshold_time=0.22,
+ drag_threshold_time=0.2,
+ x_scale=1.3,
+ y_scale=1.5,
+ alpha=0.15,
+ deadzone=15,
) -> None:
"""Initialization of Mouse class.
Args:
mouse_scale (float): Scale factor for mouse movement.
- click_threshold_time (float, optional): Threshold time for registering a click. Defaults to 0.2.
- drag_threshold_time (float, optional): Threshold time for registering a drag. Defaults to 0.15.
+ click_threshold_time (float, optional): The click_threshold_time is the minimum time interval between two consecutive clicks to register them as separate clicks.
+ If you increase click_threshold_time, you will need to wait longer between two clicks for them to be considered separate clicks.
+ If you decrease click_threshold_time, you can click faster and still register them as separate clicks.
+ drag_threshold_time (float, optional): The drag_threshold_time is the maximum time interval after which a mouse movement after a click is considered a drag rather than a separate click.
+ If you increase drag_threshold_time, you will have more time to move the mouse after clicking without triggering a drag.
+ If you decrease drag_threshold_time, even a slight movement of the mouse shortly after clicking can be considered a drag rather than a separate click.
"""
+ if click_threshold_time <= drag_threshold_time:
+ raise Exception(
+ "drag_threshold_time must be less than click_threshold_time"
+ )
+
pyautogui.FAILSAFE = False
pyautogui.PAUSE = 0
- self.mouse_scale = mouse_scale
+ self.mouse_sensitivity = float(mouse_sensitivity)
+ self.x_scale = float(x_scale)
+ self.y_scale = float(y_scale)
+ self.deadzone = deadzone
+
self.click_threshold_time = click_threshold_time
self.drag_threshold_time = drag_threshold_time
self.left_down = False
@@ -23,6 +46,12 @@ def __init__(
self.last_time = time.time()
self.console = GestureConsole()
+ # expontial moving average stuff
+ self.x_window = []
+ self.y_window = []
+ self.window_size = 12
+ self.alpha = alpha
+
def control(self, x: float, y: float, mouse_button: str):
"""Moves the mouse to XY coordinates and can perform single clicks, or click and drags when called repeatelly
@@ -32,28 +61,65 @@ def control(self, x: float, y: float, mouse_button: str):
mouse_button (string): can be "", "left", "middle", or "right"
"""
x = int(
- ((self.mouse_scale) * x - (self.mouse_scale - 1) / 2)
+ (
+ (self.x_scale * self.mouse_sensitivity) * x
+ - (self.x_scale * self.mouse_sensitivity - 1) / 2
+ )
* pyautogui.size().width
)
y = int(
- ((self.mouse_scale) * y - (self.mouse_scale - 1) / 2)
+ (
+ (self.y_scale * self.mouse_sensitivity) * y
+ - (self.y_scale * self.mouse_sensitivity - 1) / 2
+ )
* pyautogui.size().height
)
- if mouse_button == "":
- # un-click
- if self.left_down:
- pyautogui.mouseUp(button="left", _pause=False)
- self.left_down = False
- if self.middle_down:
- pyautogui.mouseUp(button="middle", _pause=False)
- self.middle_down = False
- if self.right_down:
- pyautogui.mouseUp(button="right", _pause=False)
- self.right_down = False
- self.move(x, y)
+
+ # Check if the movement is smaller than the specified radius
+ last_x, last_y = pyautogui.position()
+ distance = math.sqrt((x - last_x) ** 2 + (y - last_y) ** 2)
+
+ # Specify the radius distance (you can adjust this value)
+ ignore_small_movement = distance <= self.deadzone
+
+ self.x_window.append(x)
+ self.y_window.append(y)
+
+ x = self.exponential_moving_average(self.x_window)
+ y = self.exponential_moving_average(self.y_window)
+
+ if len(self.x_window) > self.window_size:
+ self.x_window.pop(0)
+ self.y_window.pop(0)
+ if mouse_button == "":
+ # un-click
+ if self.left_down:
+ pyautogui.mouseUp(button="left", _pause=False)
+ self.left_down = False
+ if self.middle_down:
+ pyautogui.mouseUp(button="middle", _pause=False)
+ self.middle_down = False
+ if self.right_down:
+ pyautogui.mouseUp(button="right", _pause=False)
+ self.right_down = False
+ if not ignore_small_movement:
+ self.move(x, y)
+ else:
+ # click or click and drag
+ self.click(
+ x,
+ y,
+ mouse_button,
+ )
+
+ def is_clicking(self, tip1, tip2, click_sensitinity):
+ distance = math.sqrt(
+ (tip1.x - tip2.x) ** 2 + (tip1.y - tip2.y) ** 2 + (tip1.z - tip2.z) ** 2
+ )
+ if distance < click_sensitinity:
+ return True
else:
- # click or click and drag
- self.click(x, y, mouse_button)
+ return False
def move(self, x, y):
"""Move the mouse to the specified coordinates.
@@ -108,3 +174,9 @@ def click(self, x, y, mouse_button):
self.right_down = True
self.move(x, y)
+
+ def exponential_moving_average(self, data):
+ ema = [data[0]]
+ for i in range(1, len(data)):
+ ema.append(self.alpha * data[i] + (1 - self.alpha) * ema[i - 1])
+ return ema[len(data) - 1]
diff --git a/source/gesture inference/RenderHands.py b/source/gesture inference/RenderHands.py
index 4f1d3af86..f09daf17c 100644
--- a/source/gesture inference/RenderHands.py
+++ b/source/gesture inference/RenderHands.py
@@ -4,22 +4,23 @@
class RenderHands:
"""Given the Mediapipe hands output data, renders the hands in a normilzed view or camera perspective view on a pygame surface"""
- def __init__(self, surface, render_scale=3):
+ def __init__(self, render_scale=3):
"""Create Render Hand object using a pygame surface and a scaling factor
Args:
surface (pygame.surface): pygame surface to render a hand on
hand_scale (float): multiplier to change the size at which the hand is rendered at
"""
- self.surface = surface
self.hand_scale = render_scale
self.font = pygame.font.Font("freesansbold.ttf", 30)
self.last_velocity = [(0.5, 0.5)]
+ self.thickness = 15
+ self.colors = [(0, 0, 255), (0, 255, 0), (255, 0, 0), (255, 255, 255)]
- def set_render_scale(self, scale:float):
+ def set_render_scale(self, scale: float):
self.hand_scale = scale
- def connections(self, landmarks, mode):
+ def connections(self, landmarks, mode, surface):
"""Renders lines between hand joints
Args:
@@ -29,9 +30,9 @@ def connections(self, landmarks, mode):
xy = []
- w, h = self.surface.get_size()
+ w, h = surface.get_size()
- for index, hand in enumerate(landmarks):
+ for index, hand in enumerate([landmarks]):
xy.append([])
for point in hand:
if mode:
@@ -51,91 +52,77 @@ def connections(self, landmarks, mode):
for hand in range(len(xy)):
# thumb
- self.render_line(xy[hand][0], xy[hand][1])
- self.render_line(xy[hand][1], xy[hand][2])
- self.render_line(xy[hand][2], xy[hand][3])
- self.render_line(xy[hand][3], xy[hand][4])
+ self.render_line(xy[hand][0], xy[hand][1], surface)
+ self.render_line(xy[hand][1], xy[hand][2], surface)
+ self.render_line(xy[hand][2], xy[hand][3], surface)
+ self.render_line(xy[hand][3], xy[hand][4], surface)
# index
- self.render_line(xy[hand][0], xy[hand][5])
- self.render_line(xy[hand][5], xy[hand][6])
- self.render_line(xy[hand][6], xy[hand][7])
- self.render_line(xy[hand][7], xy[hand][8])
+ self.render_line(xy[hand][0], xy[hand][5], surface)
+ self.render_line(xy[hand][5], xy[hand][6], surface)
+ self.render_line(xy[hand][6], xy[hand][7], surface)
+ self.render_line(xy[hand][7], xy[hand][8], surface)
# middle
- self.render_line(xy[hand][9], xy[hand][10])
- self.render_line(xy[hand][10], xy[hand][11])
- self.render_line(xy[hand][11], xy[hand][12])
+ self.render_line(xy[hand][9], xy[hand][10], surface)
+ self.render_line(xy[hand][10], xy[hand][11], surface)
+ self.render_line(xy[hand][11], xy[hand][12], surface)
# ring
- self.render_line(xy[hand][13], xy[hand][14])
- self.render_line(xy[hand][14], xy[hand][15])
- self.render_line(xy[hand][15], xy[hand][16])
+ self.render_line(xy[hand][13], xy[hand][14], surface)
+ self.render_line(xy[hand][14], xy[hand][15], surface)
+ self.render_line(xy[hand][15], xy[hand][16], surface)
# pinky
- self.render_line(xy[hand][0], xy[hand][17])
- self.render_line(xy[hand][17], xy[hand][18])
- self.render_line(xy[hand][18], xy[hand][19])
- self.render_line(xy[hand][19], xy[hand][20])
+ self.render_line(xy[hand][0], xy[hand][17], surface)
+ self.render_line(xy[hand][17], xy[hand][18], surface)
+ self.render_line(xy[hand][18], xy[hand][19], surface)
+ self.render_line(xy[hand][19], xy[hand][20], surface)
# knuckle
- self.render_line(xy[hand][5], xy[hand][9])
- self.render_line(xy[hand][9], xy[hand][13])
- self.render_line(xy[hand][13], xy[hand][17])
+ self.render_line(xy[hand][5], xy[hand][9], surface)
+ self.render_line(xy[hand][9], xy[hand][13], surface)
+ self.render_line(xy[hand][13], xy[hand][17], surface)
- def render_line(self, start, end):
+ def render_line(self, start, end, surface):
"""Wrapper function for pygame's render line. Will render a white line with width=5
Args:
start (int): line start position
end (int): line end position
"""
- pygame.draw.line(self.surface, (255, 255, 255), start, end, 5)
-
- def render_hands(
- self, result, mode, origins, velocity
- ):
-
- self.surface.fill((0, 0, 0))
- # Render hand landmarks
-
- w, h = self.surface.get_size()
- if result.handedness != []:
- if mode:
- hand_points = result.hand_world_landmarks
- pygame.draw.circle(self.surface, (255, 0, 255), (0.5 * w, 0.5 * h), 5)
- pygame.draw.line(
- self.surface,
- (255, 255, 0),
- ((velocity[0][0] + 0.5) * w, (velocity[0][1] + 0.5) * h),
- ((0.5) * w, (0.5) * h),
- 3,
- )
- self.last_velocity = velocity
-
- else:
- hand_points = result.hand_landmarks
-
- self.connections(hand_points, mode)
- if hand_points:
- # define colors for different hands
-
- hand_color = 0
- colors = [(0, 0, 255), (0, 255, 0), (255, 0, 0), (255, 255, 255)]
- # get every hand detected
- for index, hand in enumerate(hand_points):
- # each hand has 21 landmarks
- pygame.draw.circle(
- self.surface,
- (255, 0, 255),
- (origins[index][0] * w, origins[index][1] * h),
- 5,
- )
- for landmark in hand:
- self.__render_hands_pygame(
- colors[hand_color],
- landmark.x,
- landmark.y,
- mode,
- )
- hand_color += 1
+ pygame.draw.line(surface, (255, 255, 255), start, end, self.thickness)
+
+ def render_hands(self, landmarks, mode, origins, velocity, surface, hand_color=0):
- def __render_hands_pygame(self, color, x, y, mode):
+ surface.fill((0, 0, 0))
+
+ w, h = surface.get_size()
+
+ if mode:
+ pygame.draw.line(
+ surface,
+ (255, 255, 0),
+ ((velocity[0][0] + 0.5) * w, (velocity[0][1] + 0.5) * h),
+ ((0.5) * w, (0.5) * h),
+ self.thickness,
+ )
+ self.last_velocity = velocity
+
+ self.connections(landmarks, mode, surface)
+
+ # pygame.draw.circle(
+ # surface,
+ # (255, 0, 255),
+ # (origins[index][0] * w, origins[index][1] * h),
+ # 5,
+ # )
+ for landmark in landmarks:
+ self.__render_hands_pygame(
+ self.colors[hand_color],
+ landmark.x,
+ landmark.y,
+ mode,
+ surface
+ )
+
+
+ def __render_hands_pygame(self, color, x, y, mode, surface):
"""Renders a single landmark of a hand in pygame and scales the hand.
Args:
@@ -147,7 +134,7 @@ def __render_hands_pygame(self, color, x, y, mode):
mode (bool): True to render in normalized mode. False for world coordinates
"""
- w, h = self.surface.get_size()
+ w, h = surface.get_size()
if mode:
x *= self.hand_scale
@@ -155,5 +142,4 @@ def __render_hands_pygame(self, color, x, y, mode):
x += 0.5
y += 0.5
- pygame.draw.circle(self.surface, color, (x * w, y * h), 5)
-
+ pygame.draw.circle(surface, color, (x * w, y * h), self.thickness // 2)
diff --git a/source/gesture inference/inference.py b/source/gesture inference/inference.py
index e30901f7b..3dc996ac9 100644
--- a/source/gesture inference/inference.py
+++ b/source/gesture inference/inference.py
@@ -2,6 +2,9 @@
# https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html
# https://pygame-menu.readthedocs.io/en/latest/_source/add_widgets.html
import pydoc
+
+# this is the community edition of pygame
+# pygame-ce
import pygame
import pygame_menu
from GetHands import GetHands
@@ -10,6 +13,7 @@
from Keyboard import Keyboard
import os
from Console import GestureConsole
+import textwrap
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
@@ -21,11 +25,14 @@
clock = pygame.time.Clock()
flags = {
- "render_hands_mode": False,
+ "render_hands_mode": True,
"gesture_vector": [],
"number_of_hands": 2,
"move_mouse_flag": False,
"run_model_flag": True,
+ "gesture_model_path": "simple.pth",
+ "click_sense": 0.05,
+ "hands": None,
}
console = GestureConsole()
@@ -39,12 +46,9 @@ def main() -> None:
window = pygame.display.set_mode((window_width, window_height), pygame.RESIZABLE)
pygame.display.set_caption("Test Hand Tracking Multithreaded")
- hands_surface = pygame.Surface((window_width, window_height))
- hands_surface.set_colorkey((0, 0, 0))
-
- myRenderHands = RenderHands(hands_surface, render_scale=3)
+ renderHands = RenderHands(render_scale=3)
- mouse_controls = Mouse(mouse_sensitivity=2)
+ mouse = Mouse()
keyboard = Keyboard(
threshold=0, toggle_key_threshold=0.3, toggle_mouse_func=toggle_mouse
@@ -52,10 +56,7 @@ def main() -> None:
# control_mouse=mouse_controls.control,
hands = GetHands(
- myRenderHands.render_hands,
- control_mouse=mouse_controls.control,
flags=flags,
- keyboard=keyboard,
)
menu = pygame_menu.Menu(
@@ -66,43 +67,76 @@ def main() -> None:
)
menu.add.selector(
- "Render Mode :", [("World", False), ("Normalized", True)], onchange=set_coords
+ "Render Mode :", [("Normalized", True), ("World", False)], onchange=set_coords
)
- def change_hands_num(value):
+ def change_mouse_smooth(value, smooth):
+ nonlocal mouse
+ mouse.x_window = []
+ mouse.y_window = []
+ mouse.window_size = smooth
+ menu.add.selector(
+ "Mouse Smoothing :",
+ [("None", 1), ("Low", 2), ("Medium", 6), ("High", 12), ("Max", 24)],
+ default=3,
+ onchange=change_mouse_smooth,
+ )
+
+ def change_hands_num(value):
flags["number_of_hands"] = value[1] + 1
+ build_hands()
+
+ menu.add.dropselect(
+ "Number of hands :", ["1", "2", "3", "4"], onchange=change_hands_num
+ )
+
+ models = find_files_with_ending(".pth")
+
+ def change_gesture_model(value):
+ flags["gesture_model_path"] = value[0][0] # tuple within a list for some reason
+ build_hands()
+
+ menu.add.dropselect("Use Gesture Model :", models, onchange=change_gesture_model)
+
+ def set_click_sense(value, **kwargs):
+ nonlocal hands
+ flags["click_sense"] = value / 1000
+
+ menu.add.range_slider(
+ "Click Sensitivity",
+ default=70,
+ range_values=(1, 150),
+ increment=1,
+ onchange=set_click_sense,
+ )
+
+ def build_hands():
nonlocal hands
hands.stop()
hands.join()
hands = GetHands(
- myRenderHands.render_hands,
- control_mouse=mouse_controls.control,
flags=flags,
- keyboard=keyboard,
)
+ flags["hands"] = hands
hands.start()
- menu.add.dropselect(
- "Number of hands :", ["1", "2", "3", "4"], onchange=change_hands_num
- )
-
- menu.add.button("Close Menu", pygame_menu.events.CLOSE)
menu.add.button("Turn On Model", action=toggle_model)
menu.add.button("Turn On Mouse", action=toggle_mouse)
menu.add.button("Quit", pygame_menu.events.EXIT)
menu.enable()
- game_loop(
- window,
- hands,
- hands_surface,
- menu,
- )
+ game_loop(window, hands, menu, mouse, keyboard, renderHands)
pygame.quit()
+def find_files_with_ending(ending: str, directory_path=os.getcwd()):
+ """returns a list of tuples of the strings found"""
+ files = [(file,) for file in os.listdir(directory_path) if file.endswith(ending)]
+ return files
+
+
def toggle_mouse() -> None:
"""Enable or disable mouse control"""
console.print("toggling mouse control")
@@ -127,28 +161,49 @@ def set_coords(value, mode) -> None:
def game_loop(
window: pygame.display,
hands: GetHands,
- hands_surface: pygame.Surface,
menu: pygame_menu.Menu,
+ mouse: Mouse,
+ keyboard: Keyboard,
+ renderHands: RenderHands,
):
- """Runs the pygame event loop and renders surfaces
-
- Args:
- window (_type_): The main pygame window
- hands (_type_): The GetHands class
- hands_surface (_type_): The surface that the hands are rendered on
- menu (_type_): the main menu
- """
+ """Runs the pygame event loop and renders surfaces"""
hands.start()
running = True
is_menu_showing = True
- is_webcam_fullscreen = False
-
+ webcam_mode = 1
+ show_debug_text = True
is_fullscreen = False
+ counter = 0
+ delay_AI = None
+ window_width, window_height = pygame.display.get_surface().get_size()
+
+ hand_surfaces = []
+ for i in range(4):
+ hand_surfaces.append(pygame.Surface((window_width, window_height)))
+ hand_surfaces[i].set_colorkey((0, 0, 0))
+
+ wrapper = textwrap.TextWrapper(width=20)
+ instructions = "F1 to change webcam place. F2 to hide this text. F3 to change hand render mode. 'M' to toggle mouse control. 'G' to toggle gesture model."
+ instructions = wrapper.wrap(text=instructions)
while running:
- # window_width, window_height = menu.get_window_size() # what? idk
+ counter += 1
+
+ # changing GetHands parameters creates a new hands object
+ if flags["hands"] != None and hands != flags["hands"]:
+ hands = flags["hands"]
+
+
window_width, window_height = pygame.display.get_surface().get_size()
+
window.fill((0, 0, 0))
+
+ keys = pygame.key.get_pressed()
+ if keys[pygame.K_SPACE]:
+ console.table(["key pressed"], [["space"]], table_number=1)
+ else:
+ console.table(["key pressed"], [[""]], table_number=1)
+
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
@@ -169,59 +224,135 @@ def game_loop(
menu.enable()
if event.key == pygame.K_F1:
- is_webcam_fullscreen = not is_webcam_fullscreen
+ webcam_mode += 1
+
+ if event.key == pygame.K_F2:
+ show_debug_text = not show_debug_text
+
+ if event.key == pygame.K_F3:
+ flags["render_hands_mode"] = not flags["render_hands_mode"]
if event.key == pygame.K_F11:
is_fullscreen = not is_fullscreen
pygame.display.toggle_fullscreen()
+ if event.key == pygame.K_m:
+ keyboard.press("m")
+
+ if event.key == pygame.K_g:
+ flags["run_model_flag"] = not flags["run_model_flag"]
+
+ location = hands.location.copy()
+
+ if flags["move_mouse_flag"] and location != []:
+ mouse_button_text = ""
+ hand = hands.result.hand_world_landmarks[0]
+ if mouse.is_clicking(hand[8], hand[4], flags["click_sense"]):
+ mouse_button_text = "left"
+ location = location[0]
+ mouse.control(location[0], location[1], mouse_button_text)
+
+ if flags["run_model_flag"] and len(hands.confidence_vectors) > 0:
+ # send only the first hand confidence vector the gesture model output
+ keyboard.gesture_input(hands.confidence_vectors[0])
+ else:
+ keyboard.release()
+
# frames per second
fps = font.render(
str(round(clock.get_fps(), 1)) + "fps", False, (255, 255, 255)
)
- frame = hands.frame
- img_pygame = pygame.image.frombuffer(
- frame.tostring(), frame.shape[1::-1], "BGR"
- )
+ frame = hands.frame.copy()
+ img_pygame = pygame.image.frombuffer(frame.tobytes(), frame.shape[1::-1], "BGR")
img_width = img_pygame.get_width()
img_height = img_pygame.get_height()
- hand_surface_copy = pygame.transform.scale(
- hands_surface.copy(), (img_width * 0.5, img_height * 0.5)
- )
- img_pygame = pygame.transform.scale(
- img_pygame, (img_width * 0.5, img_height * 0.5)
- )
-
-
+ for i in range(4):
+ hand_surfaces[i] = pygame.transform.scale(
+ hand_surfaces[i], (img_width * 0.5, img_height * 0.5)
+ )
- if is_webcam_fullscreen:
+ # fullscreen webcam
+ if webcam_mode % 3 == 0:
+ renderHands.thickness = 15
img_pygame = pygame.transform.scale(
img_pygame, (window_width, window_height)
)
- hand_surface_copy = pygame.transform.scale(
- hands_surface.copy(), (window_width, window_height)
+ for i in range(4):
+ hand_surfaces[i] = pygame.transform.scale(
+ hand_surfaces[i], (window_width, window_height)
+ )
+ window.blit(img_pygame, (0, 0))
+ # windowed webcam
+ elif webcam_mode % 3 == 1:
+ renderHands.thickness = 5
+ img_pygame = pygame.transform.scale(
+ img_pygame, (img_width * 0.5, img_height * 0.5)
)
-
- window.blit(img_pygame, (0, 0))
-
- for index in range(len(hands.gestures)):
- gesture_text = font.render(hands.gestures[index], False, (255, 255, 255))
- window.blit(gesture_text, (window_width - window_width // 5, index * 40))
-
- delay_AI = font.render(
- str(round(hands.delay, 1)) + "ms", False, (255, 255, 255)
- )
- window.blit(fps, (0, 0))
- window.blit(delay_AI, (0, 40))
+ window.blit(img_pygame, (0, 0))
+ # no webcam
+ elif webcam_mode % 3 == 2:
+ pass
+ # use this again for putting hands in the corners
+ img_width = hand_surfaces[0].get_width()
+ img_height = hand_surfaces[0].get_height()
+
+ if hands.location != []:
+ for index in range(hands.num_hands_deteced):
+ if flags["render_hands_mode"]:
+ landmarks = hands.result.hand_world_landmarks
+ else:
+ landmarks = hands.result.hand_landmarks
+ for i in range(hands.num_hands_deteced):
+ renderHands.render_hands(
+ landmarks[i],
+ flags["render_hands_mode"],
+ hands.location,
+ hands.velocity,
+ hand_surfaces[i],
+ i,
+ )
+ else:
+ for i in range(4):
+ hand_surfaces[i].fill((0, 0, 0))
+
+ if show_debug_text:
+ for index in range(len(hands.gestures)):
+ gesture_text = font.render(
+ hands.gestures[index], False, (255, 255, 255)
+ )
+ window.blit(gesture_text, (0, index * 40 + 80))
+
+ if hands.delay != 0 and counter % 60 == 0:
+ delay_AI = font.render(
+ "Webcam: " + str(round(1000 / hands.delay, 1)) + "fps",
+ False,
+ (255, 255, 255),
+ )
+ if delay_AI != None:
+ window.blit(delay_AI, (0, 40))
+ window.blit(fps, (0, 0))
+
+ for index, instruc in enumerate(instructions):
+ instructoins_text = font.render(instruc, False, (255, 255, 255))
+ window.blit(instructoins_text, (0, 400 + index * 40))
if menu.is_enabled():
menu.update(events)
menu.draw(window)
- window.blit(hand_surface_copy, (0, 0))
+ corners = [
+ (0, 0),
+ (window_width - img_width, 0),
+ (0, window_height - img_height),
+ (window_width - img_width, window_height - img_height),
+ ]
+
+ for i in range(hands.num_hands_deteced):
+ window.blit(hand_surfaces[i], corners[i])
+ # clock.tick(pygame.display.get_current_refresh_rate())
clock.tick(60)
pygame.display.update()
| |